来帮助菜鸟
来源:百度知道 编辑:UC知道 时间:2024/07/12 18:37:43
要求用户输入一个字符串,然后统计字符串中空格的数量(要求使用指针来遍历数组) 代码越详细越好啊 谢谢
#include <stdio.h>
int main(void)
{
char buf[1000];
char *p;
int c;
printf("Please enter a string\n");
gets(buf);
p = buf;
c = 0;
while (*p != '\0')
{
if (*p == ' ')
c++;
p++;
}
printf("There are %d blanks in this string\n", c);
return 0;
}