27 lines
564 B
C
27 lines
564 B
C
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <unistd.h>
|
|
#include <fcntl.h>
|
|
|
|
#define SZBUF 256
|
|
|
|
int main(int argc, char const *argv[]){
|
|
char buf[SZBUF];
|
|
int fd,n,m;
|
|
if (argc<2){
|
|
fprintf(stderr,"Usage : %s <SR_FILE> \n",argv[0]);
|
|
exit (1);
|
|
} fd=open (argv[1], O_WRONLY|O_TRUNC|O_CREAT,0b00);
|
|
if (fd==-1){
|
|
perror("Opening destination file fails");
|
|
exit(2);
|
|
} write (1,"Numb --> ",9);
|
|
while (n=read(0,buf,SZBUF)){
|
|
m=write(fd,buf,n);
|
|
if (m==-1){
|
|
perror("Writing in file fails");
|
|
exit(3);
|
|
}write (1,"Numb --> ",9);
|
|
} close(fd);
|
|
exit(0);
|
|
} |