[英]ISO C++ forbids comparison between pointer and integer : File handling in C error
I am trying to read from file. 我正在尝试从文件中读取。 After reading, I want to display it's contents. 阅读后,我想显示它的内容。 My program looks like : 我的程序看起来像:
#include <stdio.h>
#include <string.h>
#include <stdio.h>
int main(int argc, char const *argv[])
{
//
char array_of_input[10][10];
FILE *fp;
fp = fopen("input.txt","r+");
int i = 0,j = 0;
char ch;
while ( !feof(fp))
{
ch = (char)fgetc(fp);
printf("%c\n", ch );
if ( ch == " ")
{
continue;
}
else if ( ch == "\n")
{
i++ ;
j = 0 ;
}
else
{
array_of_input[i][j] = ch;
j++;
}
}
return 0;
}
But, I am getting error: 但是,我得到了错误:
ISO C++ forbids comparison between pointer and integer [-fpermissive] if ( ch == " ") 如果(ch ==“”),ISO C ++禁止在指针和整数[-fpermissive]之间进行比较
fgetc(fp)
returns int and then it's type-cast to char
. fgetc(fp)
返回int,然后将其类型转换为char
。 I can't see any integer here. 我在这里看不到任何整数。
ch
is a char
- you should compare it to a char
literal (denoted by single quotes), not a string literal (denoted by double quotes): ch
是一个char
-您应该将其与一个char
文字(用单引号引起来)而不是一个字符串文字(用双引号引起来)进行比较:
if ( ch == ' ')
{
continue;
}
else if ( ch == ' ')
{
i++ ;
j = 0 ;
}
else // rest of code snipped
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.