Skip to content

Instantly share code, notes, and snippets.

@halit
Last active December 16, 2015 15:49
Show Gist options
  • Select an option

  • Save halit/5459080 to your computer and use it in GitHub Desktop.

Select an option

Save halit/5459080 to your computer and use it in GitHub Desktop.
My cat program
/*
* =====================================================================================
*
* Filename: cat.c
*
* Description: My cat program
*
* Version: 1.0
* Created: 25-04-2013 13:58:45
* Compiler: gcc
*
* Author: Halit Alptekin, info@halitalptekin.com
*
* =====================================================================================
*/
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
FILE *ip;
char *fname = argv[0];
void copyFile(FILE *, FILE *);
if(argc == 1){
copyFile(stdin, stdout);
}else{
while(--argc > 1){
if((ip = fopen(*++argv, "r")) != NULL){
copyFile(ip, stdout);
fclose(ip);
}else{
fprintf(stderr, "%s: dosya acilamadi %s\n",fname, *argv);
exit(1);
}
}
}
if(ferror(stdout)){
fprintf(stderr, "%s: standart cikis hatasi\n", fname);
exit(2);
}
return 0;
}
void copyFile(FILE *ifp, FILE *ofp){
int c;
while((c = fgetc(ifp)) != EOF) fputc(c, ofp);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment