Jump to content
  • Advertisement

Archived

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

uncutno

simple string question... anyone?

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

im trying to read a name from a file. its binary, so i cant use fin >> name; to get the different chars into a char[] is simple, but waht more does fin >> name add to the string? i use a space to signal that the name is finished, and this works fine! if i have fin = ifstream; char name[32]; fin >> name; func(name); //(char *text), it sends as char[12] (if 12 is the length of the word),not as a char[32] (as in the length of the name arrya)! my question is: what more then the chars does fin >> name; add to name[]? -Anders-Oredsson-Norway-

Share this post


Link to post
Share on other sites
Advertisement
Figured it out by myselfe :-)

if we have a char text[12],
and we add "word" to it, we need to add a 0, and -51 for the rest, to make it the same as a normal string!

char text[12] = "word"
char text[12] =
''w'' ''o'' ''r'' ''d'' 0 -51 -51 -51 -51 -51 -51 -51
in char number format!

I case anyone wondered!

-Anders-Oredsson-Norway-

Share this post


Link to post
Share on other sites
Just FYI, anything after the 0-character doesn''t matter, it doesn''t have to be -51, just ignore anything after the 0-character.

This is because strings in C and C++ are NUL terminated (NUL is the ascii character with value zero). so any function that manipulates or reads strings will only treat the data before the 0 as valid string-data. Anything after it is ignored.

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!