以下是引用missu_1314在2012-2-7 22:49:35的发言:
#include
#include
main()
{
char a[300];
int i;
printf("please input:\n");
for (i=0; ; i++)
{
scanf("%c", &a);
if (a == '\n')
break;
}
printf("the numbers of string is: %d", i);
getch();
}
稍微改了下,现在空格也算了,应该没问题吧
早点结了算了。还是有问题。下面这个能这题理清思路#include
#include
main()
{
char a[300];
int i;
printf("please input:\n");
for (i=0; ; i++)
{
scanf("%c", &a);
if (a == '\n')
break;
}
printf("the numbers of string is: %d", i);
getch();
}
稍微改了下,现在空格也算了,应该没问题吧
程序代码:#include <stdio.h>
int main(){
char word[80];
int words=0;
bool flag=false;
gets(word);
for(int i=0;word[i]!='\0';i++)
{
if (word[i]!=' '&&flag==false)
{
flag=true;
}
if (word[i]==' '&&flag==true)
{
flag=false;
words++;
}
}
printf("%d\n",++words);
}[ 本帖最后由 a271885843 于 2012-2-7 23:03 编辑 ]

认为事物非黑即白是缺智慧的表现……







