Jump to content
  • Advertisement

Archived

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

Esap1

Simple fscanf Question

This topic is 6921 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 a file contained this: [25.3,25.2,25.1] Could I just go: fscanf(file,"%f",&f1); fscanf(file,"%f",&f2); fscanf(file,"%f",&f3); Would f1 = 25.3 f2 = 25.2 and f3 = 25.1 Thanks in Advance(and sorry for such a stupid question)

Share this post


Link to post
Share on other sites
Advertisement
I believe you can do:

fscanf("[%f, %f, %f]", &f1, &f2, &f3);

But I havn''t used fscanf in a while (C++).
Never be afraid to experiment!
Also, one small note... good variable names
are important.

Share this post


Link to post
Share on other sites
You can't do

fscanf(file,"%f",&f1);
fscanf(file,"%f",&f2);
fscanf(file,"%f",&f3);

Since the file looks like this:

[25.3,25.2,25.1]

See that the formatting is different? You want to read 3 floats seperated by spaces or newlines, but in the actual file, there are [ and ] chars and the floats are separeted by commas.

If you want to use your code, you'll have to format your file like so:

25.3 25.2 25.1

Or you could use Taulin's solution, and format your file the way you did, and read it using

fscanf("[%f,%f,%f]", &f1, &f2, &f3);

And btw Taulin, there was a little problem with your code, you used spaces between the commas in the format string, which would cause it not to work...

/. Muzzafarath

Edited by - Muzzafarath on 5/7/00 3:44:04 AM

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!