#include #define BUFLEN 512 void mycat1(char * filename); void mycat2(char * filename); char* fn="myfile.txt"; int main() { FILE * fp; fp = fopen(fn,"w"); fprintf(fp,"Hello this is the first line of my file\n"); fprintf(fp,"Line 2\n"); fputs("Line 3\n",fp); fprintf(fp,"Line 4\n"); fclose(fp); printf("Printing the file with mycat1 ...\n"); mycat1(fn); printf("Printing the file with mycat2 ...\n"); mycat2(fn); printf("END\n"); fp = fopen(fn,"w+"); fprintf(fp,"ABC\n"); fclose(fp); printf("Printing the file...\n"); mycat1(fn); printf("\n"); return 0; } void mycat1(char * filename) { FILE * fp = fopen(filename,"r"); char c=0; while ( (c=getc(fp)) !=EOF) { putchar(c); } fclose(fp); return; } void mycat2(char * filename) { char buf[BUFLEN]; FILE * fp = fopen(filename,"r"); while(fgets(buf,BUFLEN,fp)) fprintf(stdout,"%s",buf); /* Note this is identical to printf */ fclose(fp); return; }