by Dinesh Thakur Category: Function and Pointer

Another commonly required string operation is that of converting the case of a given string. The C standard library does not provide any function for case conversion. However, some C implementations provide the strlwr and strupr functions. The strlwr function converts all characters in a given string to lowercase, whereas the strupr function converts all characters to uppercase. Typical calls to these functions take the following forms:

strlwr (s);

strupr (s);

Note that these functions modify the string passed as an argument and return a pointer to the modified string. The program segment given below converts (and prints) a string to uppercase and lowercase representations.

char str[] = "EVERYTHING is fair in LOVE and WAR";

printf("Uppercase: %s\n", strupr(str));

printf("Lowercase: %s\n", strlwr(str));

The output of this program segment is shown below.


Lowercase: everything is fair in love and war

Popular Article