Mega Code Archive

 
Categories / C / Code Snippets
 

Print a string in uppercase

#include <stdio.h> #include <ctype.h> void print_upper(char *string); int main(void) { char s[100]; printf("Enter a string: "); gets(s); print_upper(s); printf("\ns is now uppercase: %s", s); return 0; } void print_upper(char *string) { register int k; for(k=0; string[k]; ++k) { string[k] = toupper(string[k]); putchar(string[k]); } }