Message-ID: From: Poonam Jain To: djgpp AT delorie DOT com Subject: File opening error Date: Fri, 9 Jul 1999 10:08:27 +0530 MIME-Version: 1.0 X-Mailer: Internet Mail Service (5.5.2448.0) Content-Type: text/plain Reply-To: djgpp AT delorie DOT com I was trying to execute the code developed and compiled in RHIDE. Application was giving error while opening the file(say temp.dat) in write mode, though the file exists. So I changed the file opening mode from O_WRONLY to O_WRONLY|O_CREAT, deleted the file(say temp.dat).Executed the changed code. First time it runs fine but on executing it for the second time, encountered file opening error in write mode. What can be the possible reason ?? Below is the piece of code, I was trying to execute. Is there anything wrong in the code?? #include #include #include #include typedef struct { int magic; char c; }test_struct; main() { int fd; test_struct test; test_struct in_data,out_data; _fmode=O_BINARY; in_data.magic=10; in_data.c='A'; if(( fd = open("temp.dat", O_WRONLY)) < 0) { printf("Not able to open the file for writing \n"); return; } write(fd,&in_data,sizeof(in_data)); close(fd); if(( fd = open("temp.dat", O_RDONLY)) < 0) { printf("Not able to open the file for reading \n"); return; } read(fd,&out_data,sizeof(out_data)); close(fd); printf("Output magic %d and char %c \n",out_data.magic,out_data.c); } Regards Poonam