What do I do wrong?
Jonathan I. Kamens
jik at athena.mit.edu
Fri Dec 14 07:51:32 AEST 1990
(Note the Followup-To. This is not a wizard-level question, by any stretch
of the imagination.)
In article <1990Dec13.023035.19793 at IRO.UMontreal.CA>, quennevi at IRO.UMontreal.CA (Charles Quenneville) writes:
|> #include <pwd.h>
|> #include <stdio.h>
|>
|> main ()
|> {
|> struct passwd *pwd;
|> struct passwd *getpwent();
|>
|> setpwent("/etc/passwd");
This should either be
setpwent();
or
setpwfile("/etc/passwd");
setpwent();
Although your program will work the way you have it, it's still wrong.
|> while ((pwd = getpwent()) != 0)
|> {
|> printf("\n", pwd->pw_name);
This should be
printf ("%s\n", pwd->pw_name);
This is the bug that's causing your program to fail.
|> fflush(stdout);
This is unnecessary, as long as your stdout is line-buffered, and it almost
certainly is. Once again, your program will work with this line, but you
probably don't need it.
|> }
|> endpwent("/etc/passwd");
This should be
endpwent();
Once again, not a required change, but it's still wrong the way you have it.
|> }
\begin{small-simmering-flame}
Don't you think that all of these problems are just a bit too basic for you to
be asking the entire Usenet about them? Isn't there anybody at your site with
whom you could have consulted before sending a message to the entire net?
\end{small-simmering-flame}
--
Jonathan Kamens USnail:
MIT Project Athena 11 Ashford Terrace
jik at Athena.MIT.EDU Allston, MA 02134
Office: 617-253-8085 Home: 617-782-0710
More information about the Comp.unix.questions
mailing list