Jump to content
  • Advertisement

Archived

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

MichaelNolan

"\"%S\"" - It dosen't work!

This topic is 5563 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

Hey, I have a text file, e.g. 123 125 127 "Hello" World I want to read in the "Hello" part of it after reading in the numbers, char *MySrting ; fscanf(TheFile, "\"%s\"", &MyString); Result: MyString = "" Why?

Share this post


Link to post
Share on other sites
Advertisement
in case you didn''t understand .. the problem with your code is ONE TOO MANY levels of indirection on your character buffer ...

a char * is already the right type to pass to scanf and fscanf ... so you DO NOT want to use the & operator as well ..

Share this post


Link to post
Share on other sites
There''s another problem. You need to allocate some space for MyString to hold the string that''s scanned in. fscanf won''t modify MyString or allocate any space for you, it just modifies whatever MyString points to (and right now it doesn''t point at anything useful).

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!