From: Endlisnis Newsgroups: comp.os.msdos.djgpp Subject: Re: Problem compiling program with command-line arguments Date: Wed, 09 Sep 1998 18:38:53 -0300 Organization: NBTel Internet Lines: 33 Message-ID: <35F6F56C.73902E48@unb.ca> References: NNTP-Posting-Host: fctnts10c05.nbnet.nb.ca Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Precedence: bulk Goh Yong Kwang wrote: > =================================================== > #include > > // This program prints out all arguments passed to it from the command. > > main(char *argv[], char argc){ > while (argc){ > puts (argv[argc]); > argc--; > } > return 0; > } > > // end of program. > =================================================== Problem #1: You have the arguments backwards. Problem #2: 'argc' should be an 'int'. Problem #3: You are access one entry too high in the argv array. Your while loop should be: while(argc>=0){ argc--; puts(argv[argc]); } -- (\/) Endlisnis (\/) s257m AT unb DOT ca Endlisnis AT GeoCities DOT com Endlis AT nbnet DOT nb DOT ca