home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / sys / mac / programm / 19699 < prev    next >
Encoding:
Text File  |  1992-12-11  |  1.5 KB  |  58 lines

  1. Path: sparky!uunet!elroy.jpl.nasa.gov!ames!agate!usenet.ins.cwru.edu!b61539.student.cwru.edu!user
  2. From: yjc@po.cwru.edu (Jerome 'TofuSoft' Chan)
  3. Newsgroups: comp.sys.mac.programmer
  4. Subject: Re: Porting simple UNIX programs to the MAC??
  5. Followup-To: comp.sys.mac.programmer
  6. Date: 12 Dec 1992 00:56:22 GMT
  7. Organization: The Tofu Society of Singapore
  8. Lines: 44
  9. Distribution: na
  10. Message-ID: <yjc-111292194824@b61539.student.cwru.edu>
  11. References: <1992Dec11.161544.12668@news.eng.convex.com> <1992Dec11.214417.21082@den.mmc.com>
  12. NNTP-Posting-Host: b61539.student.cwru.edu
  13.  
  14. > > I have has a MAC for a while and have ThinkC 4.  I have just started trying to port
  15. > > simple UNIX programs to the MAC.  How does one port programs that need command line
  16. > > arguments? NOTE_ I am running System 6.0.7.
  17. > > 
  18. > > I have a modest example - fabricated for this question:
  19. > > 
  20. > > #include    <stdio.h>
  21. > > 
  22. > > void main(int argc, char **argv)
  23. > > {
  24. > >   ++argv ;
  25. > >   if ( argc < 2 ) {
  26. > >     fprintf(stderr, "usage: how number\n") ;
  27. > >     exit(1) ;
  28. > >   }
  29. > >   printf("The number is %d\n", atoi(*argv)) ;
  30. > > }
  31. > > 
  32.  
  33. I'm not sure how it's done under Think C 4.x but under Think C 5.x, you
  34. would use the ccommand() function.
  35.  
  36. It's on page 122 of the Standard Library Reference. Here is a sample
  37. program.
  38.  
  39. #include    <stdio.h>
  40. #include    <console.h>    /*Needed for ccommand*/
  41.  
  42. main(int argc, char **argv)
  43. {
  44.     int    i;
  45.  
  46.     argc = ccommand(&argv) ;
  47.  
  48.     for (i=0; i<argc; i++)
  49.         printf("%s ", argv[i]    ;
  50.  
  51.     printf("\n")    ;
  52. }
  53.  
  54. I hope that helps!
  55.  
  56. ---
  57. The Evil Tofu
  58.