char toupper(char c)
{
return (c >= 'a' && c <= 'z') ? c - 32 : c;
}
char tolower(char c)
{
return (c >= 'A' && c <= 'Z') ? c + 32 : c;
}
char * toupper_s(char *str)
{
char *ret_str;
ret_str = str;
while(str && *str) {
*str = toupper(*str);
str++;
}
return ret_str;
}
char * tolower_s(char *str)
{
char *ret_str;
ret_str = str;
while(str && *str) {
*str = tolower(*str);
str++;
}
return ret_str;
}
int main(int argc, char* argv[])
{
const char * str = "A Quick Brown Fox Jumps over the lazy dog.";
char *str_upper;
char *str_lower;
str_upper = _strdup(str);
str_lower = _strdup(str);
tolower_s(str_lower);
toupper_s(str_upper);
printf("Original string : %s\n", str);
printf("Uppercase string : %s\n", str_upper);
printf("Lowercase string : %s\n", str_lower);
free(str_upper);
free(str_lower);
}
Output:
Original string : A Quick Brown Fox Jumps over the lazy dog.
Uppercase string : A QUICK BROWN FOX JUMPS OVER THE LAZY DOG.
Lowercase string : a quick brown fox jumps over the lazy dog.
About our authors: Team EQA
You have viewed 1 page out of 252. Your C learning is 0.00% complete. Login to check your learning progress.
‹
#
›