也就是从文件中读取数据,你看下边的行吗?#include
{char str[16]; /*存放地址*/
int num;
FILE *fp;
printf("Input the address of the file:");
gets(str);
fp=fopen(str,"r");
if(!fp) exit(0);
num=jishu(fp);
printf("\nThe number of words is %d",num);
system("pause");
return 0;
}int jishu(FILE *fp)
{ char ch;
int number,target;
number=target=0;
while((ch=fgetc(fp))!=EOF)
{ if(ch!=' '&&target==0)
number++,target++; /*在空格后出现非空格,单词数量加一*/
else if(ch!=' ') target++; /*一个单词,计数器不变*/
else if (ch==' ') target=0; /**遇到空格,设置标志/
}
return number;
}
在dev c++编译器中运行成功……