home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / simtel / sigm / vols200 / vol228 / append.c < prev    next >
Encoding:
C/C++ Source or Header  |  1986-02-10  |  1.8 KB  |  113 lines

  1.  
  2. /*
  3. **    append.c    
  4. **
  5. **    public domain use only    Mark Ellington 
  6. **
  7. **    This program appends two files to make a third, larger file.
  8. **    Arguments are taken from the command line.  Text files only. 
  9. **
  10. */
  11.  
  12. /*
  13.    append two files into destination file  
  14. */
  15.  
  16. #include printf.c
  17.  
  18.  
  19. int fptr, f1ptr, f2ptr;
  20. char temp[30];
  21. static char ins[100];
  22.  
  23.  
  24. main(argc,argv)
  25. int argc; char *argv[];
  26. {
  27. char *s, *sc;
  28. char sv[3];
  29. char c;
  30.  
  31.     if (argc != 4) {
  32.         printf("\nusage: append [infilename1.ext] "); 
  33.         printf("[infilename2.ext] [outfile.ext]");
  34.                 exit();
  35.     }
  36.  
  37.     if ((f1ptr = fopen(argv[1],"r")) == 0) {
  38.         printf("\nCan't open %s\n",argv[1]);
  39.         exit();
  40.     }
  41.     printf("\n%s open to read",argv[1]);
  42.  
  43.  
  44.     if ((f2ptr = fopen(argv[2],"r")) == 0) {
  45.         printf("\nCan't open %s\n",argv[2]);
  46.         exit();
  47.     }
  48.     printf("\n%s open to read\n",argv[2]);
  49.  
  50.  
  51.     if ((fptr = fopen(argv[3],"w")) == 0) {
  52.         printf("\nCan't open %s\n",argv[3]);
  53.         exit();
  54.     }
  55.     printf("\n%s open to write\n",argv[3]);
  56.  
  57.  
  58.     transfer(f1ptr);
  59.  
  60.     transfer(f2ptr);
  61.  
  62.     printf("\n\nExiting append\n");
  63.  
  64.     fclose(fptr);
  65.     fclose(f1ptr);
  66.     fclose(f2ptr);
  67. }
  68.  
  69.  
  70. transfer(ptr)
  71. int ptr; 
  72. {
  73.     while (fgets(ptr) != 0) {
  74.         fputs(fptr);
  75.     } 
  76.     fputs(fptr);
  77. }
  78.  
  79.  
  80. fgets(f)
  81. int f; 
  82. {
  83.     char ch, *s;
  84.     s = ins;
  85.     while ((ch = getc(f)) != -1) {
  86.         *s++ = ch;
  87.         if (ch == '\n') {
  88.             *s = '\0';
  89.             return(1);
  90.         }
  91.     }
  92.     *s = '\0';
  93.     return(0);
  94. }    
  95.     
  96.  
  97. fputs(f)
  98. int f;
  99. {
  100.     char *s;
  101.     s = ins;
  102.     while(*s) putc(*s++,f);
  103. }
  104.  
  105.  
  106.  
  107.  
  108.  
  109.  
  110.  
  111.  
  112.  
  113.