sscanf format specifier warning on iPhone

Moderator
Posts: 3,577
Joined: 2003.06
Post: #1
I'm stumped. Here's the code:

Code:
char string[1024];
if (sscanf(line, "sceneName %1023[^\r\n]", &string) == 1)
{
    strncpy(scene->name, string, 1023);
}

Here's the warning it produces for the sscanf line:

Format '%1023[^

Admittedly, I'm not a sscanf expert, so maybe I'm doing this all wrong. My intention is to read a line of text, up to 1023 characters, into string, from the source line in a text file, which would look something like this in the file:
sceneName myFancySceneName

... but not to grab any newline or return if it finds one.

I don't receive this warning on the Mac, and the code works fine as far as I can tell, but when compiling for iPhone it gives this warning, so clearly the compiler thinks I'm being dumb. Am I?

What should I do? Am I doing this wrong, or what?
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #2
Presumably that's not the whole error message... my guess is Xcode misparsed it. Take a look at the detailed build log.
Quote this message in a reply
Moderator
Posts: 3,577
Joined: 2003.06
Post: #3
Man, I don't even know how to get the detailed build log anymore in Xcode since they took away the little icon for it and I don't even know how to install the Xcode documentation to read where to find it (Help->Xcode help just gives me a blank window Mad ). I installed this SDK for iOS 4.1 yesterday for a new iPhone app we're working on, so I haven't figured out the new batch of Xcode misery I have to deal with yet. Annoyed

So anyway... Yes, that is the entire message, as far as I've been able to determine. I right-click on the message and select copy and then paste into a text editor to read it, but that's the extent of the message. It looks misparsed to me as well.

If I right-click and select "Open these results as a transcript text file" it just shows a blank window.
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #4
OK, well, Xcode sucks. Don't use it.

1) it's GCC's problem, not Xcode's, largely:

Code:
$ cat test.c
#include <stdio.h>
#include <string.h>
struct S { char *name; };
void foo(char const *line, struct S *scene){
char string[1024];
if (sscanf(line, "sceneName %1023[^\r\n]", &string) == 1)
{
    strncpy(scene->name, string, 1023);
}
}
$ gcc -Werror test.c
cc1: warnings being treated as errors
test.c: In function ‘foo’:
test.c:6: warning: format ‘%1023[^
’ expects type ‘char *’, but argument 3 has type ‘char (*)[1024]’

2) it's that & that's at fault:

Code:
$ cat test.c
#include <stdio.h>
#include <string.h>
struct S { char *name; };
void foo(char const *line, struct S *scene){
char string[1024];
if (sscanf(line, "sceneName %1023[^\r\n]", string) == 1)
{
    strncpy(scene->name, string, 1023);
}
}
$ gcc -Werror test.c
Undefined symbols:
  "_main", referenced from:
      start in crt1.10.6.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
Quote this message in a reply
Moderator
Posts: 3,577
Joined: 2003.06
Post: #5
Thanks a bunch! ... I couldn't. quite. connect the idea to compile a test case straight into gcc to see if it'd give me a more coherent message.

Yes, Xcode sucks. As per your prior suggestion months ago, I am still learning to use make (with TextMate, which is indeed quite nice) when I have the opportunities. I can use make for simple projects now, no problem, but I'm still learning how to deal with more complex cases. I learned a lot from ThemsAllTook's template, but I haven't quite connected the remaining details I need. Some day though, I shall be set free! FREEEEEE!
Quote this message in a reply
Moderator
Posts: 3,577
Joined: 2003.06
Post: #6
As a follow-up, the reason I didn't get the warnings for the Mac build was that I was using LLVM 1.5, which apparently, for whatever reason, didn't catch the blatant error on my part. I'm surprised I missed it myself, but fatigue conspired against me.

The timeline goes:
1) coder (me) gets tired and does a bonehead
2) LLVM 1.5 fails to catch the error, but code works anyway
3) GCC 4.2 catches the error but errors itself on the error message
4) Xcode thinks the newline in the error is the end of the error message (not Xcode's fault, really)
5) Xcode refuses to give me the detailed build log, which really is Xcode's fault (although I'll never know if the output would have been screwed up there too)
6) coder is confused and posts code with error plainly visible and still misses it, probably because of error confusion
7) OSC has enough sense to recognize a screwy error message and goes directly to GCC to confirm
8) message is still screwy but at least points out the problem
9) bug resolved
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  What format to use for streaming background music on the iphone? AdrianM 4 4,351 Aug 7, 2009 11:29 AM
Last Post: bware218
  What file sound format, sound format and library do you use? riruilo 10 7,532 Dec 27, 2008 01:32 PM
Last Post: AnotherJake