| www.delorie.com/archives/browse.cgi | search |
| From: | Endlisnis <s257m AT unb DOT ca> |
| 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: | <Pine DOT SOL DOT 3 DOT 91 DOT 980909100830 DOT 11862A-100000 AT mercury> |
| NNTP-Posting-Host: | fctnts10c05.nbnet.nb.ca |
| Mime-Version: | 1.0 |
| To: | djgpp AT delorie DOT com |
| DJ-Gateway: | from newsgroup comp.os.msdos.djgpp |
Goh Yong Kwang wrote:
> ===================================================
> #include <stdio.h>
>
> // 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
| webmaster | delorie software privacy |
| Copyright © 2019 by DJ Delorie | Updated Jul 2019 |