home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / snip9707.zip / PRNTSELF.C < prev    next >
C/C++ Source or Header  |  1997-07-05  |  886b  |  46 lines

  1. /* +++Date last modified: 05-Jul-1997 */
  2.  
  3. /*
  4. **  PRNTSELF.C - A program which prints its own source
  5. **
  6. **  public domain demo by Bob Stout
  7. */
  8.  
  9. #include <stdio.h>
  10. #include <string.h>
  11.  
  12. #ifdef __WATCOMC__
  13.  #pragma off (unreferenced);
  14. #endif
  15.  
  16. #ifdef __TURBOC__
  17.  #pragma argsused
  18. #endif
  19.  
  20. main(int argc, char *argv[])
  21. {
  22.       FILE *in;
  23.       char fname[13], *ptr;
  24.       char line[1024];        /* Nice & roomy   */
  25.  
  26.       /*
  27.       ** Get the source name by replacing the executable's COM or EXE with C
  28.       */
  29.  
  30.       strcpy(fname, argv[0]);
  31.       ptr = strrchr(fname, '.');
  32.       strcpy(++ptr, "C");
  33.  
  34.       /*
  35.       ** Print its own source
  36.       */
  37.  
  38.       if (NULL != (in = fopen(fname, "r")))
  39.       {
  40.             while (NULL != fgets(line, 1024, in))
  41.                   fputs(line, stdprn);
  42.             return 0;
  43.       }
  44.       else  return -1;
  45. }
  46.