输不出答案,但找不到哪有错,各位帮忙看看
#include <stdio.h>void main()
{
//file *fpt;
FILE *fpt;
int count=0,space=1;
char ch,filename[20];
printf("Input the filename:");
//getchar(filename);
gets(filename);
if((fpt=fopen(filename,"r"))=NULL)
{
printf("Can't open file %s\n",filename);
return;
}
//while((ch=fputc(fpt))==EOF)
while((ch=fgetc(fpt))!=EOF)
switch(ch)
{
case ' ':
case '\t':
//case '\n': space=0;
case '\n':space=1;
break;
default: if(space)
{
space=0;
count++;
}
}
//close(fpt);
fclose(fpt);
printf("File '%s' contains %d words.\n",filename,count);
}