dclaydon
asked on
sscanf and CString - why don't it work?
G'Day all
Why does this code not work?
CString text;
int a;
CString b;
file->ReadString(text);
sscanf(text, "%i\t%s", a, b);
What happens is an Access violation error.
'file' is a CStdioFile that has been opened correctly.
text is reading correctly (contains that text "1 fred").
If I change 'a' to be a CString and modify the sscanf appropriately, 'a' and 'b' both become the last string that was scanned.
This program is being written using MS VC++ ver4.2 under Win NT 4.0.
How do I get around this, such that both objects are read correctly?
Regards
Dave
Why does this code not work?
CString text;
int a;
CString b;
file->ReadString(text);
sscanf(text, "%i\t%s", a, b);
What happens is an Access violation error.
'file' is a CStdioFile that has been opened correctly.
text is reading correctly (contains that text "1 fred").
If I change 'a' to be a CString and modify the sscanf appropriately, 'a' and 'b' both become the last string that was scanned.
This program is being written using MS VC++ ver4.2 under Win NT 4.0.
How do I get around this, such that both objects are read correctly?
Regards
Dave
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I always seem to forget the & with scanf functions.
CStrings have some quirks with them (which most people forget).
Thanks