Using gcc (GCC) 4.6.2 in C89 mode.
I am wondering if my sscanf has been implemented correctly?
I am trying to just get just the port number from this SDP string which is contained in element, the port number is '49462'.
m=audio 49462 RTP/AVP 0 8
I am using sscanf like this:
sscanf(element, "%*s %d", &sdp.audio_port);
So it will ignore the first string part 'm=audio' and then get the port number, which is what I want.
The final part of the string after the port number can be ignored. In fact there could be more audio formats specified i.e. 0 8 94 101, etc. So the string length could verify. However, it's just the audio port I am interested in and nothing else.
Would I need any format specified for the rest of the string?
I was getting some memory issues, and am wondering if this could be the cause.
sscanfsees an integer literal whose value doesn't fit in anint, its behavior is undefined. This means there's no portable way to detect or handle such an error. If you're sure before callingsscanf()that this won't be an issue, you can use it; otherwise, you'll have to roll your own parser, probably usingstrtol().