isspace为"大约QUOT发生问题的; [英] Probems about "isspace"
本文介绍了isspace为"大约QUOT发生问题的;的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
困难出现在我的家庭作业一次。
我写一个程序来计算一个文本文件中的空白字符数。
我用isspace为算吧。在文本文件中的内容为1 1 1,但仍然计数器0,什么是错的$ C $的CS?
的#includestdafx.h中
#包括文件ctype.h
INT _tmain(INT ARGC,_TCHAR *的argv [])
{FILE *输入;
焦X;
INT空间= 0;输入= FOPEN(123.txt,R);而((的fscanf(输入%C,&安培; X))== 1)
{
如果(isspace为(X))
空间++;
}的printf(空间:%d个\\ N,空格);返回0;
}
解决方案
正如我以前指出的那样,你需要使用龟etc(),而不是fscanf()函数。 fscanf()函数不读whitepace。
Difficulties appear in my homework again. I am writing a program to count the number of whitespace characters in a text file. I use "isspace" to count it. The content in the text file is "1 1 1", but the counter still 0, what's wrong of the codes?
#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;
}
解决方案
As I've pointed out before, you need to use fgetc(), not fscanf(). fscanf() doesn't read whitepace.
这篇关于isspace为"大约QUOT发生问题的;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文