我正在编写一个程序来计算文本文件中空白字符的数量。 我用“isspace”来计算它。文本文件中的内容是“1 1 1”,但是计数器还是0,代码有什么问题吗?
#include "stdafx.h"
#include "ctype.h"
int _tmain(int argc, _TCHAR* argv[])
{
FILE* input;
char x;
int space = 0;
input = fopen("123.txt", "r");
while ((fscanf(input, " %c", &x)) == 1)
{
if (isspace(x))
space++;
}
printf("space : %d\n", space);
return 0;
}
最佳答案
scanf 系列函数将自动跳过格式字符串中出现的空格。考虑改用 fgetc
。
关于c - 关于 "isspace"的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1896837/