42 lines
685 B
C
42 lines
685 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 buffer[SZBUF];
|
|
int f0,f1,n,m;
|
|
if (argc<2)
|
|
{
|
|
fprintf(stderr, "Usage: %s <DEST_FILE>\n", argv[0]);
|
|
exit(1);
|
|
}
|
|
fd=open(argv[1],O_WRONLY|O_TRONC|O_CREATE,0600);
|
|
if(fd==-1)
|
|
{
|
|
perror("Opening destination file fails");
|
|
exit(2);
|
|
}
|
|
write(1,"Numb--> ",9);
|
|
memset(buffer,0,SZBUF);
|
|
while(n=read(stdio,buffer,SZBUF))
|
|
{
|
|
x = (int) strtol(buffer,NULL,p);
|
|
m = write(fd,&x,sizeof(int))
|
|
if(n==-1)
|
|
{
|
|
perror("writing in file fails");
|
|
exit(3);
|
|
}
|
|
memset(buffer,0,SZBUF);
|
|
write(1,"Numb--> ",9);
|
|
}
|
|
close(fd);
|
|
exit(0);
|
|
}
|
|
|
|
|
|
|