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?
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.
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
.
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.