简体   繁体   English

ISO C ++禁止比较指针和整数:C错误中的文件处理

[英]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.

相关问题 错误] ISO C++ 禁止指针和整数之间的比较 [-fpermissive] - Error] ISO C++ forbids comparison between pointer and integer [-fpermissive] ISO C++ 禁止指针和整数之间的比较 [-fpermissive]| [C] - ISO C++ forbids comparison between pointer and integer [-fpermissive]| [C] ISO C++ 禁止在 Arduino c 串行通信中比较指针和整数 [-fpermissive] 错误 - ISO C++ forbids comparison between pointer and integer [-fpermissive] error in Arduino c serial communication ISO C ++禁止在devc ++中比较指针和整数[-fpermissive]错误 - ISO C++ forbids comparison between pointer and integer [-fpermissive] error in devc++ C编译器错误:“指针与整数之间的比较”。 - C compiler error: “comparison between a pointer and an integer”. ISO C ++禁止可变大小的数组(编译错误) - ISO C++ forbids variable-size array (compilation error) C中指针和整数的比较 - Comparison between pointer and integer in C ISO C ++禁止在转换为c ++的旧代码中增加类型为&#39;void *&#39;的指针 - ISO C++ forbids incrementing a pointer of type ‘void*’ , in legacy code converted to c++ 错误 - 禁止指针和整数之间的比较以及如何将用户输入用于其他函数? - error- forbids comparison between pointer and integer and how to use user input to other function? 在 C 程序中显示错误:警告:指针和整数之间的比较 - Showing error in C program : warning: comparison between pointer and integer
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM