C language to determine the English character case
- 2020-04-02 03:17:01
- OfStack
C language isupper() function: determine whether the character is uppercase or not
The header file:
#include <ctype.h>
Definition function:
int isupper(int c);
Check whether the parameter c is capitalized.
Return value: returns non-0 if parameter c is uppercase; otherwise returns 0.
Note: this is a macro definition, not a real function.
Example: find an uppercase character in the string STR.
#include <ctype.h>
main(){
char str[] = "123c@#FDsP[e?";
int i;
for(i = 0; str[i] != 0; i++)
if(isupper(str[i]))
printf("%c is an uppercase charactern", str[i]);
}
Execution results:
F is an uppercase character
D is an uppercase character
P is an uppercase character
C islower() function: determines whether a character is lowercase
The header file:
#include <ctype.h>
Islower () is used to determine whether a character is lowercase. The prototype is:
int islower(int c);
[parameter] c is the character to be detected.
[return value] if the parameter c is lowercase, a non-zero value is returned; otherwise, 0 is returned.
Note that this is a macro definition, not a real function.
Example: determines which lowercase letters are in the STR string.
#include <ctype.h>
main(){
char str[] = "123@#FDsP[e?";
int i;
for(i = 0; str[i] != 0; i++)
if(islower(str[i]))
printf("%c is a lower-case charactern", str[i]);
}
Output results:
c is a lower-case character
s is a lower-case character
e is a lower-case character