File reading question
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.
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.
Put your data on seperate lines instead or do it the "real" way; don''t save to textfile, instead save your struct.
______________________________Only dead fish go with the main-stream.
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 );
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 );
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement