Message-ID: <3785A4D2.398B0B27@accord-soft.com> Date: Fri, 09 Jul 1999 12:59:22 +0530 From: Sunil V Organization: Accord Software & Systems Pvt. Ltd. X-Mailer: Mozilla 4.6 [en] (Win95; I) X-Accept-Language: en MIME-Version: 1.0 To: djgpp AT delorie DOT com Subject: Re: File opening error References: Content-Type: multipart/mixed; boundary="------------D5AA1BB291C59C406D127937" Reply-To: djgpp AT delorie DOT com This is a multi-part message in MIME format. --------------D5AA1BB291C59C406D127937 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Poonam Jain wrote: > 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. The application worked well when I used just O_WRONLY. coz' O_WRONLY opens file for writing. Hence assumes that 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 ?? Instead what u can do is use only O_CREAT and everything works fine. > > 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 -- _______________________________________________________________________ Imagination is more important than knowledge. - Albert Einstein _______________________________________________________________________ --------------D5AA1BB291C59C406D127937 Content-Type: text/x-vcard; charset=us-ascii; name="sunilv.vcf" Content-Transfer-Encoding: 7bit Content-Description: Card for Sunil V Content-Disposition: attachment; filename="sunilv.vcf" begin:vcard n:V;Sunil tel;home:341 4609 tel;work:556 0136 / 138 / 105 x-mozilla-html:FALSE org:Accord Software & Systems Pvt. Ltd.;Software Division adr:;;;;;; version:2.1 email;internet:sunilv AT accord-soft DOT com x-mozilla-cpt:;-3328 fn:Sunil V end:vcard --------------D5AA1BB291C59C406D127937--