| tianajrp (23) | |||
What's wrong with this code?
for some reason my : fscanf(myPlayerFile, "%s", &lol); // s had no value (bad pointer) how do i fix it? | |||
|
Last edited on
|
|||
| Fransje (237) | |
You should use a C-style string: .Also look at this: http://www.cplusplus.com/reference/cstdio/fscanf/ | |
|
Last edited on
|
|
| tianajrp (23) | |||
|
Im using String for the character name in a class that why im using string plus here is the else part:
the fprint in here allow string to work i dont see what i did wrong that give me bad pointer at all | |||
|
|
|||
| Smac89 (195) | |
line 6 in your first post:fscanf(myPlayerFile, "%s", &lol); should be fscanf(myPlayerFile, "%s", lol);
| |
|
|
|
| Fransje (237) | |
I think fprint allows it here because you use the .c_str() part, which returns a C-string.But what you can do is get the input in a C-style string, and then pass that string to Player.setName().
| |
|
|
|
| tianajrp (23) | |||
When i do that i get access violation error
can you please show me an example? as in convert Char to string and such (if that is what you mean) | |||
|
|
|||
| Fransje (237) | |||
lol is converted to a std::string (using the std::string constructor) when it is passed to setName(). | |||
|
Last edited on
|
|||
| tianajrp (23) | |
|
holy cow it's worked thank you very much :D :3 i didnt know a char will be converted to a string upon the %s comment, but now i know, thank you very much :3 | |
|
|
|
| Fransje (237) | |
| you're welcome :) | |
|
|
|