Reputation: 39
I am confused as to why I get this warning[Warning] comparison between pointer and integer
while (fread(&searchrecord, sizeof(record), 1, fl) != NULL)
How I fix it?
Upvotes: 2
Views: 921
Reputation: 234695
fread
returns a size_t
value which is an unsigned integral type. Your platform is defining NULL
as (void*)0
which is a pointer type.
Your compiler issues a warning since you're comparing these unrelated types.
The solution is to drop the != NULL
in your condition:
while (fread(&searchrecord,sizeof(record),1,fl))
which is clearer anyway.
Upvotes: 5
Reputation: 144715
fread
returns the number of items successfully read from the stream. You should compare that to the actual number you passed:
while (fread(&searchrecord, sizeof(record), 1, fl) == 1)
If you try and read more than one item, you should store the return value and compare that to 0
.
Upvotes: 0