• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: sscanf problem
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.

References: 
 >sscanf problem (From: David Dauer <email@hidden>)

  • Prev by Date: Re: Name instance variables, methods and parameters.
  • Next by Date: Re: sscanf problem
  • Previous by thread: Re: sscanf problem
  • Next by thread: Re: sscanf problem
  • Index(es):
    • Date
    • Thread