Mega Code Archive

 
Categories / C / Code Snippets
 

Convert string to upper case and lower case

#include <ctype.h> #include <stdio.h> int main(void) { char s[80]; int j; printf("Enter a string: "); gets(s); for( j = 0; s[ j ]; j++) s[ j ] = toupper( s[ j ] ); printf("%s\n", s); /* uppercase string */ for(j = 0; s[ j ]; j++) s[j] = tolower(s[ j ]); printf("%s\n", s); /* lowercase string */ return 0; }