home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / lang / c / 20208 < prev    next >
Encoding:
Text File  |  1993-01-26  |  1.9 KB  |  71 lines

  1. Newsgroups: comp.lang.c
  2. Path: sparky!uunet!pipex!mfmail!rma
  3. From: rma@mfltd.co.uk (Richard M. Ashton (x5422))
  4. Subject: Re: Could someone answer my question....thanks
  5. Message-ID: <1993Jan26.085508.21611@mfltd.co.uk>
  6. Sender: news@mfltd.co.uk (News Login)
  7. Reply-To: rma@mfltd.co.uk
  8. Organization: Micro Focus Ltd (UK)
  9. References:  <1993Jan26.000105.10930@njitgw.njit.edu>
  10. Distribution: mf
  11. Date: Tue, 26 Jan 1993 08:55:08 GMT
  12. Lines: 57
  13.  
  14. In article <1993Jan26.000105.10930@njitgw.njit.edu>, csc5840@hertz.njit.edu (Sekhar Chitti) writes:
  15. |> Hi Netters,
  16. |> 
  17. |> 
  18. |> Following is a C program in which I tried to simulate command
  19. |> line arguments (argc, argv). I am not getting the expected
  20. |> output which should be the same as when argc, argv are used.
  21. |> 
  22. |> 
  23. |> 
  24. |> #include <stdio.h>
  25. |> 
  26. |> main(arg1,arg2)
  27. |> int arg1;
  28. |> char *arg2[];
  29. |> {
  30. |>     int i;
  31. |>     for(i=0;i<arg1;i++)
  32. |>         puts("%d - %s",i,arg2[i]);
  33. |> }
  34. |> 
  35. |> 
  36. |> The following is the output when I tested the program for diff no.
  37. |> of arguments. The 'for' loop iterates exactly the number of arguments,
  38. |> but when I tried to print the number of args, as u can see from the
  39. |> output, I am getting it wrong...
  40. |> 
  41. |> 6:45pm C-> a.out arg2
  42. |> %d - %s
  43. |> %d - %s
  44. |> 6:45pm C-> a.out arg2 arg3
  45. |> %d - %s
  46. |> %d - %s
  47. |> %d - %s
  48. |> 6:46pm C-> a.out arg2 arg3 arg4
  49. |> %d - %s
  50. |> %d - %s
  51. |> %d - %s
  52. |> %d - %s
  53. |> 6:46pm C-> a.out 
  54. |> %d - %s
  55. |> 
  56. |> 
  57. |> Could somebody suggest me in this regard ? Thanks in advance.
  58. |> 
  59. |> Sekhar Chitti
  60.  
  61. Try reading the manual on the function puts(). 
  62. You should find that you are using the wrong function in the wrong way !! 
  63. Try a printf instead of the puts, but keep the same code after.
  64. If only people would take the time to read the manual.
  65.  
  66. -- 
  67. Richard M. Ashton      | Micro Focus,    | Tel: 0635-565422
  68. Systems Programmer,    | 26 West Street, | Fax: 0635-33966
  69. International Customer | Newbury, Berks. | rma@mfltd.co.uk
  70. Engineering Group.     | RG13 1JT.       |
  71.