Xref: utzoo comp.unix.programmer:678 comp.unix.questions:27535 comp.unix.wizards:23832 Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!wuarchive!usc!elroy.jpl.nasa.gov!ncar!gatech!udel!princeton!phoenix.Princeton.EDU!subbarao From: subbarao@phoenix.Princeton.EDU (Kartik Subbarao) Newsgroups: comp.unix.programmer,comp.unix.questions,comp.unix.wizards Subject: Re: What do I do wrong? Message-ID: <4705@idunno.Princeton.EDU> Date: 13 Dec 90 03:32:31 GMT References: <1990Dec13.023035.19793@IRO.UMontreal.CA> Sender: news@idunno.Princeton.EDU Followup-To: comp.unix.programmer Lines: 65 In article <1990Dec13.023035.19793@IRO.UMontreal.CA> quennevi@IRO.UMontreal.CA (Charles Quenneville) writes: >Hello! Hi! Say, didnt you crosspost the article before this before? I thought we went over that.... >Could you tell me what is wrong with this program? All I'm trying to do >is simply to print the username. >#include >#include Ah. I see you're going to use the right routines at least. >main () > { > struct passwd *pwd; > struct passwd *getpwent(); > > setpwent("/etc/passwd"); /* setpwent() doesn't take any arguments. * And if you were going to use fsetpwent() -- this is the default unless * you're using yellow pages and for some reason only want to search * "/etc/passwd". */ > while ((pwd = getpwent()) != 0) > { > printf("\n", pwd->pw_name); /* err..... all this does is print newlines. Shouldn't there be a * %s somewhere ? Or better yet, replace the printf() with puts(). */ > fflush(stdout); /* Another needless thing */ > } > endpwent("/etc/passwd"); /* likewise needless -- endpwent() takes no arguments either btw. */ > } This is all you need: # include # include main() { struct passwd *pwd; while (pwd = getpwent()) puts(pw->pw_name); } /* a one liner, minus includes :-) */ > Charles Quenneville > quennevi@kovic.iro.umontreal.ca > >"Ventrebleu, de par ma chandelle verte, j'aime mieux etre gueux" Don't know what this means, but: "Shouldn't you read man pages and check code before you post it to the net?" */ -Kartik -- (I need a new .signature -- any suggestions?) subbarao@{phoenix or gauguin}.Princeton.EDU -|Internet kartik@silvertone.Princeton.EDU (NeXT mail) -| SUBBARAO@PUCC.BITNET - Bitnet