A simple way to convert case to case letters in C

  • 2020-04-02 03:17:39
  • OfStack

C tolower() function: converts uppercase to lowercase
The header file:


#include <ctype.h>

Definition function:


int toupper(int c);

If the parameter c is lowercase, the corresponding uppercase letter is returned.

Return value: returns the converted uppercase, or returns the parameter c value if no conversion is required.

Example: converts the lowercase letter in the s string to an uppercase letter.


#include <ctype.h>
main(){
 char s[] = "aBcDeFgH12345;!#$";
 int i;
 printf("before toupper() : %sn", s);
 for(i = 0; i < sizeof(s); i++)
  s[i] = toupper(s[i]);
 printf("after toupper() : %sn", s);
}

Execution results:


before toupper() : aBcDeFgH12345;!#$
after toupper() : ABCDEFGH12345;!#$


C tolower() function: converts uppercase to lowercase
The header file:


#include <stdlib.h>

Definition function:


int tolower(int c);

Function description: if the parameter c is uppercase, the corresponding lowercase letter is returned.

Return value: returns the converted lowercase letter, or the parameter c value if no conversion is required.

Example: converts uppercase to lowercase letters in the s string.


#include <ctype.h>
main(){
 char s[] = "aBcDeFgH12345;!#$";
 int i;
 printf("before tolower() : %sn", s);
 for(i = 0; i < sizeof(s); i++)
  s[i] = tolower(s[i]);
 printf("after tolower() : %sn", s);
}

Execution results:


before tolower() : aBcDeFgH12345;!#$
after tolower() : abcdefgh12345;!#$


Related articles: