Repeat the usage of the gets () and is functions and repeat the getsis functions.
Here are the materials you can find from Baidu Encyclopedia:
Gets ():
Reads a string from the stdin stream,It is stopped until it receives a linefeed or EOF.And store the read results in the character array pointed to by the buffer pointer.The linefeed is not used as the content of the read string.To end the string.
Therefore, when a string is input using gets, the linefeed is read (not left in the buffer zone) and converted to null by the system.
Therefore, it is an incorrect usage:
In contrast, getchar () can use the line break as the content: After changing it
# Include <stdio. h>
# Include <string. h>
# Include <ctype. h>
Int main ()
{
Char c;
Int I = 0, j = 0, k = 0, l = 0, m = 0;
Printf ("enter a string with a length not greater than 200: \ n ");
While (c = getchar ())! = '\ N ')
{
If (isalpha (c ))
J ++;
If (isdigit (c ))
K ++;
If (isspace (c ))
L ++;
If (ispunct (c ))
M ++;
}
Printf ("the number of letters of the string: % d, number of digits: % d, number of spaces: % d, number of Punctuations: % d", j, k, l, m );
Return 0;
}
However, there are still many functions in this program for reference:
1. isalpha ()
Usage: add the header file # include (using <ctype. h> in C)
Function: determines whether the character ch is an English letter. When ch is an English letter a-z or a A-Z, the function returns a value not 1; otherwise, 0 is returned.
Likewise:
Isupper
Prototype: extern int isupper (int c );
Header file: <ctype. h>
Function: determines whether the character c is an uppercase English letter.
(When the parameter c is an uppercase English letter (A-Z), return a non-zero value, otherwise return zero.
Note: This is a macro definition, not a real function.
Islower
Islower (test whether the character is a lowercase letter)
2. isdigit
Prototype: extern int isdigit (char c );
Usage: # include <ctype. h>
Function: determines whether character c is a number.
NOTE: If c is 0-9, a non-zero value is returned. Otherwise, zero is returned.
This is a macro definition, not a real function.
3. isspace
Header file
# Include <ctype. h>
Define functions
Int isspace (int c)
Function Description
Check whether parameter c is a space character, that is, whether it is a space ('') or a horizontal positioning character.
('\ T'), return key (' \ R'), line feed ('\ n'), vertical positioning character (' \ V ') or paging ('\ F. [1]
Return Value
If the parameter c is a space character, TRUE is returned; otherwise, NULL (0) is returned ).
Additional instructions
This is a macro definition, not a real function.
4. ispunct
Header file
# Include <ctype. h>
Define functions
Int ispunct (int c)
Function Description
Check whether the parameter c is a punctuation or special symbol. Returns TRUE, that is, the parameter c is
Non-spaces, non-numbers, and non-English letters.