Xref: utzoo comp.unix.programmer:683 comp.unix.questions:27545 comp.unix.wizards:23833 Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!usc!snorkelwacker.mit.edu!bloom-picayune.mit.edu!athena.mit.edu!jik From: jik@athena.mit.edu (Jonathan I. Kamens) Newsgroups: comp.unix.programmer,comp.unix.questions,comp.unix.wizards Subject: Re: What do I do wrong? Message-ID: <1990Dec13.205132.24791@athena.mit.edu> Date: 13 Dec 90 20:51:32 GMT References: <1990Dec13.023035.19793@IRO.UMontreal.CA> Sender: news@athena.mit.edu (News system) Reply-To: jik@athena.mit.edu (Jonathan I. Kamens) Followup-To: comp.unix.programmer Organization: Massachusetts Institute of Technology Lines: 66 (Note the Followup-To. This is not a wizard-level question, by any stretch of the imagination.) In article <1990Dec13.023035.19793@IRO.UMontreal.CA>, quennevi@IRO.UMontreal.CA (Charles Quenneville) writes: |> #include |> #include |> |> 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@Athena.MIT.EDU Allston, MA 02134 Office: 617-253-8085 Home: 617-782-0710