APL/APL1.2/SCR1.2/TP11/read_file.c

23 lines
422 B
C
Raw Normal View History

2022-01-18 14:16:05 +01:00
#include<stdio.h>
#include<stdlib.h>
#include<fcntl.h>
#define BUFSIZE 256
int main(int argc, char * argv[]){
int f,n;
char buf[BUFSIZE];
if(argc<2){
fprintf(stdin,"Usage: %s <file-to-read>\n",argv[0]);
exit(1);
}
f=open(argv[1],O_RDONLY);
if(f==-1){
perror("Opening file failed !");
exit(2);
}
while((n=read(f,buf,BUFSIZE))!=0){// pas oublier les parentheses
write(1,buf,n);
close(f);
exit(0);
}
}