I would like to use fscanf to read from a file that's a list of numbers (the length is arbitrary)
42
20
8
5
0
However, I am not sure how to construct a format string that reads an arbitrary number of values like this.
Try this
while(fscanf(fp,"%d",&number) == 1)
{
printf("%d",number);
}
fscanf
returns the number of items read and returns EOF on end of file
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.