TP sur lecriture et lecture fichier
This commit is contained in:
parent
93ffb9240a
commit
b821dbde45
22
DEV1.1/TP12/copiercoller.c
Normal file
22
DEV1.1/TP12/copiercoller.c
Normal 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
0
DEV1.1/TP12/copypaste.c
Normal file
19
DEV1.1/TP12/records.c
Normal file
19
DEV1.1/TP12/records.c
Normal 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
0
DEV1.1/TP12/test.txt
Normal file
3
DEV1.1/TP12/testlol.txt
Normal file
3
DEV1.1/TP12/testlol.txt
Normal file
@ -0,0 +1,3 @@
|
||||
aaaaa
|
||||
ok normalement c good
|
||||
|
BIN
DEV1.1/TP12/top10
Normal file
BIN
DEV1.1/TP12/top10
Normal file
Binary file not shown.
1
DEV1.1/TP12/trucAcopier.txt
Normal file
1
DEV1.1/TP12/trucAcopier.txt
Normal file
@ -0,0 +1 @@
|
||||
lol ceci est un test la pukldfjbgjdk, :(
|
1
DEV1.1/TP12/trucQuiEstCopier.txt
Normal file
1
DEV1.1/TP12/trucQuiEstCopier.txt
Normal file
@ -0,0 +1 @@
|
||||
lol ceci est un test la pukldfjbgjdk, :((
|
49
DEV1.1/TP12/typewritter.c
Normal file
49
DEV1.1/TP12/typewritter.c
Normal 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;
|
||||
}
|
Loading…
Reference in New Issue
Block a user