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 == " ")
fgetc(fp)
returns int and then it's type-cast to 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):
if ( ch == ' ')
{
continue;
}
else if ( ch == ' ')
{
i++ ;
j = 0 ;
}
else // rest of code snipped
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.