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

  1. Newsgroups: comp.lang.c
  2. Path: sparky!uunet!psinntp!news.columbia.edu!cunixb.cc.columbia.edu!ss107
  3. From: ss107@cunixb.cc.columbia.edu (Sergey  Shamis)
  4. Subject: Re: Could someone answer my question....thanks
  5. Message-ID: <1993Jan26.023236.17822@news.columbia.edu>
  6. Sender: usenet@news.columbia.edu (The Network News)
  7. Nntp-Posting-Host: cunixb.cc.columbia.edu
  8. Reply-To: ss107@cunixb.cc.columbia.edu (Sergey  Shamis)
  9. Organization: Columbia University
  10. References: <1993Jan26.000105.10930@njitgw.njit.edu>
  11. Date: Tue, 26 Jan 1993 02:32:36 GMT
  12. Lines: 54
  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.  
  62. Well, as far as I know, puts() does not recognize any format
  63. specifiers (like %d, %s, etc).  It just takes a string as an argument
  64. and prints it out on the sdout.  That's why you get these results (it
  65. prints just the string, i.e. whatever is inside the quotation marks).
  66.  
  67.  
  68.