Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ionic-framework/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C 计算文件中除空格以外的单词_C - Fatal编程技术网

C 计算文件中除空格以外的单词

C 计算文件中除空格以外的单词,c,C,我试图从名为file.txt的文件中数数单词,但它给了我带空格的字符。 如何在不计算空格的情况下计算单词数 #include<stdio.h> #include<conio.h> main() { FILE *f1; char c; clrscr(); printf("data output"); f1 = fopen("file.txt","r"); while((c=getc(f1))!=EOF) { printf("%c",c); } f

我试图从名为file.txt的文件中数数单词,但它给了我带空格的字符。 如何在不计算空格的情况下计算单词数

#include<stdio.h>
#include<conio.h>
main()
{

 FILE *f1;
 char c;
 clrscr();

 printf("data output");
 f1 = fopen("file.txt","r");
 while((c=getc(f1))!=EOF)
 {
   printf("%c",c);
 }
 fclose(f1);
 getch();
}
#包括
#包括
main()
{
文件*f1;
字符c;
clrsc();
printf(“数据输出”);
f1=fopen(“file.txt”、“r”);
而((c=getc(f1))!=EOF)
{
printf(“%c”,c);
}
fclose(f1);
getch();
}
请帮我尽快解决它。 提前谢谢

// Create a char array to store a word
char word[100];
// Stop when fscanf returns 0
while(fscanf(f1, "%s", word)==1)
{
    // print the word
    printf("%s ",word);
    // Increment count
    count ++;
}
// Print count
printf("%d\n", count );

请记住,它假定单词长度不超过100个字符,因为
fscanf
不会检查缓冲区溢出

,您在上述代码中的计数准确程度如何?请尽快让我们知道<代码> ?考虑使用<代码> fgsSd()>代码>读取一行,并使用<代码> Stotok()/<代码>分隔单词和空格。我正在从文件中计数单词,但我不知道它的单词,所以它给了我Chalter的空白。如何使用Strutok()?请让我知道,因为我只有c的基本知识