APL/APL1.2/SCR1.2/TP11/store_nb_rep.c
2022-02-07 10:53:37 +01:00

33 lines
622 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);
memset(buf,0,BUFSIZE);
while(n=read(0,buf,BUFSIZE)){
x = (int)strtol(buf,NULL,0);
r=write(f,buf,sizeof(int));
if(r==-1){
perror("writing failed");
exit(3);
}
write(1,"Numb --> ",9);
memset (buf,0,BUFSIZE);
}
close(f);
exit(0);
}