septembre + octobre
This commit is contained in:
34
SCR/TP02/Q1/copy1.c
Normal file
34
SCR/TP02/Q1/copy1.c
Normal file
@@ -0,0 +1,34 @@
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <assert.h>
|
||||
|
||||
#define BLOCK_SIZE 1
|
||||
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int fin, fout;
|
||||
char buf[BLOCK_SIZE];
|
||||
|
||||
assert( argc == 3 );
|
||||
|
||||
fin = open(argv[1],O_RDONLY);
|
||||
assert( fin >= 0 );
|
||||
|
||||
fout = open(argv[2],O_CREAT|O_WRONLY|O_TRUNC,0600);
|
||||
assert( fout >= 0 );
|
||||
|
||||
while(1){
|
||||
ssize_t nb_read;
|
||||
nb_read = read(fin,buf,BLOCK_SIZE);
|
||||
if (nb_read <= 0)
|
||||
break;
|
||||
write(fout,buf,nb_read);
|
||||
}
|
||||
|
||||
close(fin);
|
||||
close(fout);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
34
SCR/TP02/Q1/copy1.c~
Normal file
34
SCR/TP02/Q1/copy1.c~
Normal file
@@ -0,0 +1,34 @@
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <assert.h>
|
||||
|
||||
#define BLOCK_SIZE 1
|
||||
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int fin, fout;
|
||||
char buf[BLOCK_SIZE];
|
||||
|
||||
assert( argc == 3 );
|
||||
|
||||
fin = open(argv[1],O_RDONLY);
|
||||
assert( fin >= 0 );
|
||||
|
||||
fout = open(argv[2],O_CREAT|O_WRONLY|O_TRUNC,0600);
|
||||
assert( fout >= 0 );
|
||||
|
||||
while(1){
|
||||
ssize_t nb_read;
|
||||
nb_read = read(fin,buf,BLOCK_SIZE);
|
||||
if (nb_read <= 0)
|
||||
break;
|
||||
write(fout,buf,nb_read);
|
||||
}
|
||||
|
||||
close(fin);
|
||||
close(fout);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
30
SCR/TP02/Q1/copy2.c
Normal file
30
SCR/TP02/Q1/copy2.c
Normal file
@@ -0,0 +1,30 @@
|
||||
#include<stdlib.h>
|
||||
#include<stdio.h>
|
||||
#include<string.h>
|
||||
|
||||
|
||||
int main(int argc, char** argv){
|
||||
FILE* fichierScr = NULL;
|
||||
FILE* fichierDes = NULL;
|
||||
char caractere[2];
|
||||
int arg=0;
|
||||
if (argc > 2){
|
||||
fichierDes = fopen(argv[2],"w");
|
||||
fichierScr = fopen(argv[1],"r");
|
||||
if (fichierScr){
|
||||
if (fichierDes){
|
||||
while (fread(caractere,sizeof(char),1,fichierScr)!=0){
|
||||
fwrite(caractere,sizeof(char),1,fichierDes);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
printf("%s n'existe pas ou ne peut pas s'ouvrir\n",argv[2]);
|
||||
return 1;
|
||||
}
|
||||
printf("%s n'existe pas ou ne peut pas s'ouvrir\n",argv[1]);
|
||||
return 1;
|
||||
}
|
||||
printf("Utilisation: argv[0] <fichier_source> <fichier_destination>\n");
|
||||
return 0;
|
||||
}
|
||||
|
BIN
SCR/TP02/Q1/dest.txt
Normal file
BIN
SCR/TP02/Q1/dest.txt
Normal file
Binary file not shown.
BIN
SCR/TP02/Q1/exe
Executable file
BIN
SCR/TP02/Q1/exe
Executable file
Binary file not shown.
BIN
SCR/TP02/Q1/origine.txt
Normal file
BIN
SCR/TP02/Q1/origine.txt
Normal file
Binary file not shown.
Reference in New Issue
Block a user