hello i am a newbie.. i had been following Beginning linux programming 4th edition. I tried to go for a sample but the data isnt getting copied to other file but the new file files.in is formed
#include<unistd.h>
#include<stdlib.h>
#include<fcntl.h>
#include<sys/types.h>
#include<stdio.h>
int main() {
char buff[]="Hello world! This is CodeZer0.I love using linux specially BackTrack4.I am concentrating on c programming\n";
char block[10];
int op,in;
int rdbyte;
op=open("files.out1",O_RDWR|O_CREAT,S_IRUSR|S_IWUSR);
write(op,buff,sizeof(buff));
if (op==-1)
write(1,"some error\n",11);
in=open("files.in",O_RDWR|O_CREAT,S_IRUSR|S_IWUSR);
if (in==-1)
write(1,"some error in files.in\n",23);
while((rdbyte=read(op,block,sizeof(block)))>0);
write(in,block,rdbyte);
return 0;
}
hello duoas.. i am a coplete newbie so its not getting clear.. i re-wrote the program with many changes where the eror was taking place.. can you explain abit more on wats the problem..
#include<unistd.h>
#include<stdlib.h>
#include<fcntl.h>
#include<sys/types.h>
#include<stdio.h>
int main() {
char block[106];
int op,in;
int rdbyte;
op=open("files.out1",O_RDWR|O_CREAT,S_IRUSR|S_IWUSR|S_IXUSR|S_IROTH|S_IWOTH|S_IXOTH);
if (op==-1)
write(1,"some error\n",11);
rdbyte=write(op,"Hello world! This is CodeZer0.I love using linux specially BackTrack4.I am concentrating on c programming\n",106);
if (rdbyte==0)
write(1,"data not written\n",17);
in=open("files.in",O_RDWR|O_CREAT,S_IRUSR|S_IWUSR|S_IXUSR|S_IROTH|S_IWOTH|S_IXOTH);
if (in==-1)
write(1,"some error in files.in\n",23);
printf("%d\n",op);
rdbyte=read(op,block,106);
if (rdbyte==0)
write(1,"data not read\n",14);
if (rdbyte==-1)
write(1,"some error\n",11);
rdbyte=write(in,block,106);
if (rdbyte==0);
write(1,"data not entered\n",17);
if (rdbyte==-1)
write(1,"some error2\n",15);
return 0;
}