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

  1. Path: sparky!uunet!paladin.american.edu!gatech!rutgers!njitgw.njit.edu!hertz.njit.edu!csc5840
  2. From: csc5840@hertz.njit.edu (Sekhar Chitti)
  3. Newsgroups: comp.lang.c
  4. Subject: Could someone answer my question....thanks
  5. Message-ID: <1993Jan26.000105.10930@njitgw.njit.edu>
  6. Date: 26 Jan 93 00:01:05 GMT
  7. Sender: news@njit.edu
  8. Organization: New Jersey Institute of Technology, Newark, N.J.
  9. Lines: 45
  10. Nntp-Posting-Host: hertz.njit.edu
  11.  
  12. Hi Netters,
  13.  
  14.  
  15. Following is a C program in which I tried to simulate command
  16. line arguments (argc, argv). I am not getting the expected
  17. output which should be the same as when argc, argv are used.
  18.  
  19.  
  20.  
  21. #include <stdio.h>
  22.  
  23. main(arg1,arg2)
  24. int arg1;
  25. char *arg2[];
  26. {
  27.     int i;
  28.     for(i=0;i<arg1;i++)
  29.         puts("%d - %s",i,arg2[i]);
  30. }
  31.  
  32.  
  33. The following is the output when I tested the program for diff no.
  34. of arguments. The 'for' loop iterates exactly the number of arguments,
  35. but when I tried to print the number of args, as u can see from the
  36. output, I am getting it wrong...
  37.  
  38. 6:45pm C-> a.out arg2
  39. %d - %s
  40. %d - %s
  41. 6:45pm C-> a.out arg2 arg3
  42. %d - %s
  43. %d - %s
  44. %d - %s
  45. 6:46pm C-> a.out arg2 arg3 arg4
  46. %d - %s
  47. %d - %s
  48. %d - %s
  49. %d - %s
  50. 6:46pm C-> a.out 
  51. %d - %s
  52.  
  53.  
  54. Could somebody suggest me in this regard ? Thanks in advance.
  55.  
  56. Sekhar Chitti
  57.