#include<stdio.h>
#define N 100
int main()
{
char *a[N];
int j=0,i=0;
printf("Please input some words :\n");
gets(*a);
while(*a[i]!='\0')
if(*a[i]==' ')
j++,i++;
printf("Words' number is %d",j);
return 0;
}
uj5u.com熱心網友回復:
char *a[N]; --->char a[N];gets(*a); ---> gets(a);
uj5u.com熱心網友回復:
#include<stdio.h>
#define N 100
int main()
{
char a[N];
int j=0,i=0;
printf("Please input some words :\n");
fgets(a, N, stdin);
while(a[i]!='\0') {
if(a[i]==' ')
j++,i++;
else
i++;
}
j++;
printf("Words' number is %d",j);
return 0;
}
供參考~
如果少了else i++,while回圈可能是死回圈~
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/111585.html
標籤:C語言
