Re: sscanf problem
Re: sscanf problem
- Subject: Re: sscanf problem
- From: lbland <email@hidden>
- Date: Wed, 28 Jan 2004 09:13:10 -0500
On Jan 28, 2004, at 8:10 AM, David Dauer wrote:
I've got a strange problem using sscanf:
const char *s;
char theString[ 256 ];
s = "123 456 \"blah\"";
int theInt1;
int theInt2;
sscanf( s, "%d %d \"%s\"", &theInt1, &theInt2, theString );
NSLog(@"%@",[NSString stringWithCString:theString]);
This returns a string 'blah"' - and i've no idea why i get a quote
sign at
the end of the string.
Anyone knows why this happens and how to fix that?
You have maybe 4 problems:
s is a "constant" string and may be in a constant mach-o header and
should not be overwritten.
use something like:
s[50];
strcpy(s, "123 456 \"blah\"");
next you need to assign theString:
strcpy(theString, "");
3, '\"' is an escape character for a quote, if you want a backslash use:
"123 456 \\\"blah\\\""
and 4: you write into s, not theString.
maybe you want something like:
theString = [NSString stringWithFormat:@"%d %d %s", theInt1, theInt2,
"blah"];
NSLog(theString);
-lance
Lance Bland
mailto:email@hidden
VVI
888-VVI-PLOT
http://www.vvi.com
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.