From 4bfb625f107a3337a6f1444badfe02293dfa0b87 Mon Sep 17 00:00:00 2001 From: andrew_programmer Date: Fri, 24 Aug 2007 20:37:38 +0000 Subject: [PATCH] Example of work with files in TinyC. git-svn-id: svn://kolibrios.org@612 a494cfbc-eb01-0410-851d-a64ba20cac60 --- .../develop/metcc/trunk/samples/files/FILES.C | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 programs/develop/metcc/trunk/samples/files/FILES.C diff --git a/programs/develop/metcc/trunk/samples/files/FILES.C b/programs/develop/metcc/trunk/samples/files/FILES.C new file mode 100644 index 0000000000..f6c8f1033e --- /dev/null +++ b/programs/develop/metcc/trunk/samples/files/FILES.C @@ -0,0 +1,43 @@ +#include +#include + +int main(int argc, char **argv) +{ + + int i; + char c; + FILE *f; + FILE *fin; + FILE *fout; + + //write to file + f=fopen("testfile.txt","w"); + + for(i=0;i<50;i++) + { + fputc('1',f); + } + fclose(f); + + //append to file + f=fopen("testfile.txt","a"); + + for(i=0;i<50;i++) + { + fputc('2',f); + } + fclose(f); + + //copy from testfile.txt to copyfile.txt + + fin=fopen("testfile.txt","r"); + fout=fopen("copyfile.txt","w"); + + while((c=fgetc(fin))!=EOF) + { + fputc(c,fout); + } + fclose(fin); + fclose(fout); + +} \ No newline at end of file