APL/APL1.2/SCR1.2/TP11/read_file2.c
2022-01-18 14:16:05 +01:00

30 lines
521 B
C

#include<stdio.h>
#include<stdlib.h>
#include<fcntl.h>
#define BUFSIZE 256
int main(int argc, char * argv[]){
int r,x,f,y,n;
char buf[BUFSIZE];
if(argc<2){
fprintf(stdin,"Usage: %s <file>\n",argv[0]);
exit(1);
}
f=open(argv[1],O_WRONLY|O_CREAT|O_TRUNC,0600);
if(f==-1){
perror("Opening file failed !");
exit(2);
}
write(1,"Numb --> ",9);
while((n=read(0,buf,BUFSIZE))!=0){
r=write(f,buf,n);
if(r==-1){
perror("writing failed");
exit(3);
}
write(1,"Numb --> ",9);
}
close(f);
exit(0);
}