C language Isspace () function: To determine whether a character is a white space character
header file:
To define a function:
Function Description: Check that parameter C is a space character, that is, whether it is a space ('), a positional character (' \ t '), a CR (' \ R '), a newline (' \ n '), a vertical positioning character (' \v '), or a page (' \f ').
Return value: If the parameter C is a white-space character, it returns a non-0, otherwise it returns 0.
Additional description: This is a macro definition, not a true function.
Example: Locate the space character contained in the string str[] and display the ASCII code for the space character.
#include <ctype.h>
Main () {
char str[] = "123c @# fd\tsp[e?\n";
int i;
for (i = 0; Str[i]!= 0. i++)
if (Isspace (str[i)))
printf ("str[%d" is a white-space character:%d\n ", I, Str[i]);
}
Execution results:
STR[4] is a white-space character:32
str[7] is a white-space character:32 str[10
] is a white-space character:9// \ t
str[16] is a white-space character:10//\ t
C language Ispunct () function: To determine whether a character is a punctuation mark or special character
header file:
The ispunct () function is used to detect whether a character is a punctuation mark or special character, and its prototype is:
"Parameter" C is the character you want to detect.
Return value if C is a punctuation mark or special symbol (non-space, non-numeric, and non-English letters) returns a value other than 0, or 0.
Note that this is a macro definition, not a true function.
"Instances" lists punctuation marks or special symbols in string str.
#include <stdio.h>
#include <ctype.h>
int main ()
{
int i=0;
int cx=0;
Char str[]= "Hello, welcome!";
while (Str[i])
{
if (ispunct (str[i)) cx++;
i++;
}
printf ("sentence contains%d punctuation characters.\n", CX);
return 0;
}
Output results:
Sentence contains 2 punctuation characters.