Mega Code Archive

 
Categories / C / Code Snippets
 

Change string case using its pointer

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