C/String/String Case
Change string case using its pointer
#include <ctype.h>
#include <stdio.h>
int main(void)
{
char str[80], *p;
printf("Enter a string: ");
gets(str);
p = str;
while( *p ) {
*p = toupper(*p);
p++;
}
printf("%s\n", str); /* uppercase string */
p = str; /* reset p */
while( *p ) {
*p = tolower(*p);
p++;
}
printf("%s\n", str); /* lowercase string */
return 0;
}
Convert string to upper case and lower case
#include <ctype.h>
#include <stdio.h>
int main(void)
{
char str[80];
int i;
printf("Enter a string: ");
gets(str);
for( i = 0; str[ i ]; i++)
str[ i ] = toupper( str[ i ] );
printf("%s\n", str); /* uppercase string */
for(i = 0; str[ i ]; i++)
str[i] = tolower(str[ i ]);
printf("%s\n", str); /* lowercase string */
return 0;
}