• Advertisement

Archived

This topic is now archived and is closed to further replies.

File reading question

This topic is 5538 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

if I have an int, character string, and double (dollar amount); on one line in a file, how can I read it into my program and store the values in variables.

Share this post


Link to post
Share on other sites
Advertisement
You will gave to parse that one line.
Put your data on seperate lines instead or do it the "real" way; don''t save to textfile, instead save your struct.

Share this post


Link to post
Share on other sites
I think what you are looking for is fscanf.

Try starting on the Stream I/O page on MSDN.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccore98/html/_crt_stream_i.2f.o.asp

Look for fscanf. You know when you use a printf and you want to format it as an int then a string then maybe a double and you go something like "%d, %s, %.2lf", someInt, someString, someFloat? Well fscanf will let you do the same thing but reading in from a file stream. So if you are reading in lines from a file you would open the file with fopen and then...

fscanf( stream, "%d %s %lf", &someInt, &someString, &someFloat );

Share this post


Link to post
Share on other sites

  • Advertisement