home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: sparky!uunet!psinntp!news.columbia.edu!cunixb.cc.columbia.edu!ss107
- From: ss107@cunixb.cc.columbia.edu (Sergey Shamis)
- Subject: Re: Could someone answer my question....thanks
- Message-ID: <1993Jan26.023236.17822@news.columbia.edu>
- Sender: usenet@news.columbia.edu (The Network News)
- Nntp-Posting-Host: cunixb.cc.columbia.edu
- Reply-To: ss107@cunixb.cc.columbia.edu (Sergey Shamis)
- Organization: Columbia University
- References: <1993Jan26.000105.10930@njitgw.njit.edu>
- Date: Tue, 26 Jan 1993 02:32:36 GMT
- Lines: 54
-
- In article <1993Jan26.000105.10930@njitgw.njit.edu> csc5840@hertz.njit.edu (Sekhar Chitti) writes:
- >Hi Netters,
- >
- >
- >Following is a C program in which I tried to simulate command
- >line arguments (argc, argv). I am not getting the expected
- >output which should be the same as when argc, argv are used.
- >
- >
- >
- >#include <stdio.h>
- >
- >main(arg1,arg2)
- >int arg1;
- >char *arg2[];
- >{
- > int i;
- > for(i=0;i<arg1;i++)
- > puts("%d - %s",i,arg2[i]);
- >}
- >
- >
- >The following is the output when I tested the program for diff no.
- >of arguments. The 'for' loop iterates exactly the number of arguments,
- >but when I tried to print the number of args, as u can see from the
- >output, I am getting it wrong...
- >
- >6:45pm C-> a.out arg2
- >%d - %s
- >%d - %s
- >6:45pm C-> a.out arg2 arg3
- >%d - %s
- >%d - %s
- >%d - %s
- >6:46pm C-> a.out arg2 arg3 arg4
- >%d - %s
- >%d - %s
- >%d - %s
- >%d - %s
- >6:46pm C-> a.out
- >%d - %s
- >
- >
- >Could somebody suggest me in this regard ? Thanks in advance.
- >
- >Sekhar Chitti
-
-
- Well, as far as I know, puts() does not recognize any format
- specifiers (like %d, %s, etc). It just takes a string as an argument
- and prints it out on the sdout. That's why you get these results (it
- prints just the string, i.e. whatever is inside the quotation marks).
-
-
-