Article View: comp.os.msdos.djgpp
Article #5Re: is there something wrong with this?...
From: Kurt Watzka
Date: Fri, 29 Dec 1995 11:19
Date: Fri, 29 Dec 1995 11:19
36 lines
1545 bytes
1545 bytes
oracle@veenet.value.net (informix) writes:
>...
> while((fgets(temp,120,fp))!=NULL) {
> sscanf(temp,"%s:%s:%*s:%*s:%*s:%*s:%*s",sent[x].name,
> sent[x].passwd);
> ++x;
> }
>...
> this was meant to read a unix password file (/etc/passwd) and
> extract the username and encrypted password field...
> can someone tell me why this is not working as planned?... it worked
> on a shitty compiler... i recently installed djgpp...
The "%s" format string does not imply that a colon is not part of a
"string". You probably want something like
while (fgets(temp,120,fp)) {
if (2 != sscanf(temp,"%[^:]:%[^:]",sent[x].name, sent[x].passwd))
printf("error in line %d\n", x + 1);
++x;
}
> should i be doing to a better way?... is it portable?...
If you want to use C, and not a language that was designed for this kind
of work, you can use scan sets. They are portable, as long as you have
an ANSI C compiler.
Kurt
--
| Kurt Watzka Phone : +49-89-2180-6254
| watzka@stat.uni-muenchen.de
| ua302aa@sunmail.lrz-muenchen.de
Technical Details
Message-ID:
<4c0isj$oi8@sparcserver.lrz-muenchen.de>Path:
arc1-ca.pugleaf.net!lrz-muenchen.de!sun2!ua302aaReferences:
<4c01cb$nu2@veenet.value.net>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!lrz-muenchen.de!sun2!ua302aa From: ua302aa@sun2.lrz-muenchen.de (Kurt Watzka) Newsgroups: comp.os.msdos.djgpp,comp.lang.c Subject: Re: is there something wrong with this?... Date: 29 Dec 1995 11:19:47 GMT Organization: Leibniz-Rechenzentrum, Muenchen (Germany) Distribution: world Message-ID: <4c0isj$oi8@sparcserver.lrz-muenchen.de> References: <4c01cb$nu2@veenet.value.net> NNTP-Posting-Host: sun2.lrz-muenchen.de