Commande "cat" sous Unix.

From Tuxunix
Jump to: navigation, search

Exemple


$ catwoman <<EOF

> Test sur entree standard

> EOF

Test sur entree standard

$ catwoman test.txt

test

mon

catwoman!


Code


   1./*
   2. * catwoman.c for (self)
   3. *
   4. * Made by tuxedo
   5. *
   6. * Started on lun 26 nov 2007 11:39:47 pterrier
   7. * Last update lun 26 nov 2007 11:52:46 pterrier
   8.*/
   9.#include <stdio.h>
  10.#include <stdlib.h>
  11.#define MAXSIZE 100
  12.   
  13.void readFile(const char *fileName, const char *typeOpen);
  14.      
  15./*readFile*/
  16.void readFile(const char *fileName, const char *typeOpen){
  17.      char character[MAXSIZE]="";
  18.      FILE *fic=NULL;
  19.       
  20.      fic=fopen(fileName, typeOpen);
  21.      if(fic != NULL){
  22.         while(fgets(character, MAXSIZE, fic) != NULL && !feof(fic)){
  23.            printf("%s", character);
  24.         }
  25.      }else{
  26.           printf("Error write file score\n");
  27.      }
  28.      fclose(fic);
  29.}/*readFile*/
  30.       
  31.int main(int argc, const char *argv[]){
  32.      if(argc == 2){
  33.         readFile(argv[1], "r");
  34.      }else{
  35.         char character[MAXSIZE]="";
  36.         while(fgets(character, MAXSIZE, stdin) != NULL){
  37.              printf("%s", character);
  38.         }
  39.      }
  40.      return 0;
  41.}

By TuXedo