Reputation: 11
#include<stdio.h>
#include<string.h>
int main(int argc,char *argv[])
{
char c;
char a[19][100];
int i=0;
int j=0;
while((c=fgetc(stdin))!=EOF)
{
if(c!=" ")
{
a[i][j]=c;
j++;
}
if(c==" "||c=='\n')
{
a[i][j]='\0';
i++;
j=0;
}
}
for(j=0;j<i;j++)
printf("%s \n",a[j]);
}
the error that i get is
15.c:12:5: warning: comparison between pointer and integer[enabled by default]
if(c!=" ")
^
15.c:17:5: warning: comparison between pointer and integer [enabled by default]
if(c==" "||c=='\n')
Upvotes: 0
Views: 666
Reputation: 113
You compare char
with char *
. You can not do it, and set c
to be signed char
because it need to store EOF
. It depends on compiler does char
will signed
or unsigned
, so you can't know.
It need to be like this:
if(c!= ' ')
{
a[i][j]=c;
j++;
}
Upvotes: -1
Reputation: 70931
c
is defined to be a char
and " "
is a "string" literal, which in C is implemtned as an array of char
s, which in turn decays to a pointer to it's 1st element, that is a char *
.
To fix this compare c
to a char
.
if (c != ' ') /* Use ' to code a char literal, use " to code a string literal. "/
Also as you assign the result of fgetc()
to c
and test c
against EOF
(which typically is -1
) make c
an int
, that is make it the type fgetc()
returns.
Upvotes: 2