From b821dbde45a5cabc79dc935270976abff2d72bf7 Mon Sep 17 00:00:00 2001 From: Simon Saye Babu Date: Wed, 23 Nov 2022 16:43:26 +0100 Subject: [PATCH] TP sur lecriture et lecture fichier --- DEV1.1/TP12/copiercoller.c | 22 ++++++++++++++ DEV1.1/TP12/copypaste.c | 0 DEV1.1/TP12/records.c | 19 ++++++++++++ DEV1.1/TP12/test.txt | 0 DEV1.1/TP12/testlol.txt | 3 ++ DEV1.1/TP12/top10 | Bin 0 -> 70 bytes DEV1.1/TP12/trucAcopier.txt | 1 + DEV1.1/TP12/trucQuiEstCopier.txt | 1 + DEV1.1/TP12/typewritter.c | 49 +++++++++++++++++++++++++++++++ 9 files changed, 95 insertions(+) create mode 100644 DEV1.1/TP12/copiercoller.c create mode 100644 DEV1.1/TP12/copypaste.c create mode 100644 DEV1.1/TP12/records.c create mode 100644 DEV1.1/TP12/test.txt create mode 100644 DEV1.1/TP12/testlol.txt create mode 100644 DEV1.1/TP12/top10 create mode 100644 DEV1.1/TP12/trucAcopier.txt create mode 100644 DEV1.1/TP12/trucQuiEstCopier.txt create mode 100644 DEV1.1/TP12/typewritter.c diff --git a/DEV1.1/TP12/copiercoller.c b/DEV1.1/TP12/copiercoller.c new file mode 100644 index 0000000..eed8c7c --- /dev/null +++ b/DEV1.1/TP12/copiercoller.c @@ -0,0 +1,22 @@ +#include +#include +#include + +int main(int argc, char const *argv[]) +{ + FILE *f; + f=fopen(argv[1],"r"); + FILE *o; + o=fopen(argv[2],"w"); + int n; + while(!feof(f)==1) + { + if(!feof(f)==1) + { + fread(&n,1,1,f); + fwrite(&n,1,1,o); + } + } + fclose(o); + fclose(f); +} \ No newline at end of file diff --git a/DEV1.1/TP12/copypaste.c b/DEV1.1/TP12/copypaste.c new file mode 100644 index 0000000..e69de29 diff --git a/DEV1.1/TP12/records.c b/DEV1.1/TP12/records.c new file mode 100644 index 0000000..5627c53 --- /dev/null +++ b/DEV1.1/TP12/records.c @@ -0,0 +1,19 @@ +#include +#include +#include + +int main(int argc, char const *argv[]) +{ + FILE *f; + f=fopen("top10","r"); + int n; + char name[3]; + for(int i = 0;i<10;i++) + { + fread(&n,4,1,f); + printf("%09d ",n); + fread(&name,1,3,f); + printf("%s \n",name); + } + fclose(f); +} \ No newline at end of file diff --git a/DEV1.1/TP12/test.txt b/DEV1.1/TP12/test.txt new file mode 100644 index 0000000..e69de29 diff --git a/DEV1.1/TP12/testlol.txt b/DEV1.1/TP12/testlol.txt new file mode 100644 index 0000000..0cf3330 --- /dev/null +++ b/DEV1.1/TP12/testlol.txt @@ -0,0 +1,3 @@ +aaaaa +ok normalement c good + diff --git a/DEV1.1/TP12/top10 b/DEV1.1/TP12/top10 new file mode 100644 index 0000000000000000000000000000000000000000..f6c571a816785dc8c14743ba17b4674c55b4c5ea GIT binary patch literal 70 zcmXqZ@nUfDce*U>#bD!ar&6QN5R +#include +#include + +int main(int argc, char const *argv[]) +{ + FILE *f; + if (argc < 2) + { + printf("usage : %s \n", argv[0]); + return EXIT_FAILURE; + } + if (argc > 1) + { + if (strcmp(argv[1],"-a")==0) + { + f=fopen(argv[2],"a"); + FILE *l; + char output[100]; + while(!feof(l)) + { + fputs(output,l); + fgets + + } + } + else + { + f=fopen(argv[2],"w"); + } + } + else + { + f=fopen(argv[1],"w"); + } + + + char input[100]={" "}; + + fgets(input, 100, stdin); + while(strcmp(input,"quit\n")!=0) + { + fputs(input,f); + fgets(input, 100, stdin); + } + + fclose(f); + return 0; +} \ No newline at end of file