1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
| #include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#define BLOCK_SIZE 512
int main(int argc,char* argv[]){
if(argc<2){
printf("Erreur ! Il n'y a pas assez d'arguments !\n");
}
else{
int fd=open(argv[2],O_RDONLY,0);
int resRead=0;
char* buffer=(char*)malloc(BLOCK_SIZE*sizeof(char));
resRead=read(fd,(char*)buffer,BLOCK_SIZE);
printf("%s\n",buffer);
while(resRead>0){
printf("%s\n",buffer);
resRead=read(fd,(char*)buffer,sizeof(buffer));
}
close(fd);
free(buffer);
}
return 0;
} |
Partager