Monday, May 24, 2010

Read specific pattern string from a file in C?

My file is something like 1 10 20 308


How can I read each value individually and store in a int or string array?

Read specific pattern string from a file in C?
all info stored in a file is stored in "char" (8 bit) format, so you would have to know which numbers were originally integers or strings (or whatever). and read them out the way they were written in.





your example 1 10 20 308:


would be stored in the file like (in HEX to make it easier):


0x01 0x0A 0x14 0x01 0x34


there isn't any way to tell what this represents unless you know how they were stored.


it could be all char which would mean 1 10 20 1 52
Reply:I believe you'd use something like this:


fscanf(filePointer, "%d", %26amp;intArray)


in a loop until fscanf returns "null" for end-of-file.

imperial

No comments:

Post a Comment