Datei: p9-2.c


    1   /*
    2    *      p9-2.c 
    3    *      Beispielprogramm 2, Abschnitt 9
    4    *      Realisierung des Kommandos cat
    5    */
    6   
    7   #include <stdio.h>
    8   
    9   void filecopy(FILE *);
   10   
   11   void main(int argc, char *argv[])
   12   {
   13     FILE *fp;
   14     
   15     if (argc == 1)        /* ohne Argumente */
   16       filecopy(stdin);    /* Standard Eingabe kopieren */
   17     else {
   18       while (--argc > 0) {
   19         if ((fp = fopen(*++argv, "r")) == NULL) {
   20   	fprintf(stderr, "cat: can't open %s\n", *argv);
   21   	exit(1);
   22         } 
   23         else {
   24   	filecopy(fp);
   25   	fclose(fp);
   26         }
   27       }
   28     }
   29     exit(0);
   30     
   31   } /* main() */
   32   
   33   /* Datei fp als Standard Ausgabe ausgeben */
   34   void filecopy(register FILE *fp)   
   35   {
   36     register int c;
   37     
   38     while ((c = getc(fp)) != EOF)
   39       putc(c, stdout);
   40       
   41   } /* filecopy() */


Erzeugt von c2html 1.01