TP sur lecriture et lecture fichier

This commit is contained in:
Simon SAYE BABU 2022-11-23 16:43:26 +01:00
parent 93ffb9240a
commit b821dbde45
9 changed files with 95 additions and 0 deletions

View File

@ -0,0 +1,22 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
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);
}

0
DEV1.1/TP12/copypaste.c Normal file
View File

19
DEV1.1/TP12/records.c Normal file
View File

@ -0,0 +1,19 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
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);
}

0
DEV1.1/TP12/test.txt Normal file
View File

3
DEV1.1/TP12/testlol.txt Normal file
View File

@ -0,0 +1,3 @@
aaaaa
ok normalement c good

BIN
DEV1.1/TP12/top10 Normal file

Binary file not shown.

View File

@ -0,0 +1 @@
lol ceci est un test la pukldfjbgjdk, :(

View File

@ -0,0 +1 @@
lol ceci est un test la pukldfjbgjdk, :((

49
DEV1.1/TP12/typewritter.c Normal file
View File

@ -0,0 +1,49 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(int argc, char const *argv[])
{
FILE *f;
if (argc < 2)
{
printf("usage : %s <arg> <filename> \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;
}