Mailing List archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[vdr] Re: sscanf



On 02 Aug 2004 "Teuling, Sieme" <Sieme.Teuling@echostar.com> wrote:

> I tried this little test program, but it also fails, also on vedora-linux
> and under winnt (I don't get the frequency)..I don't see how the
> 
> sscanf(s, "%a[^:]:%d :%a[^:]:%a[^:] :%d :%a[^:]:%a[^:]:%d :%d :%d :%d :%d
>:%d ", &namebuf, &frequency, &parambuf, &sourcebuf, &srate, &vpidbuf,
> &apidbuf, &tpid, &ca, &sid, &nid, &tid, &rid);
> 
> ..line in channels.c could have ever worked??
> 
> int main(void)
> {
>    int fields;
>    char namebuf[50];
>    int frequency=0; 
>    char *s = "701 (TV):561833"; 
> 
>    fields = sscanf(s, "%s[^:]:%d ", namebuf, &frequency ); 
>    printf("namebuf:%s frequency:%d", namebuf, frequency );
> 
> }

'%s[^:]' is meaningless. The original is '%a[^:]' where 'a' is a
flag character only and the actual conversion character is '['.
So if you want to obmit the 'a' it's simply '%[^:]'. You have to
prealloc a buffer in this case and take care to not overflow it.
Normaly one would give the allowed length as in '%32[^:]', which
would allow max 32 chars (not including the terminating NULL, so
the buffer has to be at least 33 chars).

See also: man scanf

Regards.

-- 
Stefan Huelswitt
s.huelswitt@gmx.de  | http://www.muempf.de/




Home | Main Index | Thread Index