Acquaintance pointer string of statistics spaces

Description Questions
enter a string. The method requires the use of pointers to traverse the string, and counting the number of spaces in the string.
Enter
Enter a string, no more than 999 characters, ending with a carriage return.
Output
number of spaces in the output string.
Input Example
How are you!
Output example
2
data range
input character string, the output is an integer. And the input string no more than 999 characters

#include "stdio.h"
void main()
{
char s[999],*p;
int i=0;
gets(s);
for(p=s;*p!='\0';*p++)
{
if(*p==' ')
i++;
}
printf("%d",i);

}

Guess you like

Origin blog.csdn.net/Lhw_666/article/details/91415180