home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: sparky!uunet!pipex!mfmail!rma
- From: rma@mfltd.co.uk (Richard M. Ashton (x5422))
- Subject: Re: Could someone answer my question....thanks
- Message-ID: <1993Jan26.085508.21611@mfltd.co.uk>
- Sender: news@mfltd.co.uk (News Login)
- Reply-To: rma@mfltd.co.uk
- Organization: Micro Focus Ltd (UK)
- References: <1993Jan26.000105.10930@njitgw.njit.edu>
- Distribution: mf
- Date: Tue, 26 Jan 1993 08:55:08 GMT
- Lines: 57
-
- 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
-
- Try reading the manual on the function puts().
- You should find that you are using the wrong function in the wrong way !!
- Try a printf instead of the puts, but keep the same code after.
- If only people would take the time to read the manual.
-
- --
- Richard M. Ashton | Micro Focus, | Tel: 0635-565422
- Systems Programmer, | 26 West Street, | Fax: 0635-33966
- International Customer | Newbury, Berks. | rma@mfltd.co.uk
- Engineering Group. | RG13 1JT. |
-