Re: [Dev-C++] fwrite() & fprintf() -- binary or text ???
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
From: Per W. <pw...@ia...> - 2006-07-11 22:30:09
|
Don't know what you are talking about. Test with the following source: #include <stdio.h> int main() { FILE *f; f = fopen("test.bin","wb"); if (f) { fprintf(f,"test\n\n\n"); fwrite("test\n\n\n",1,7,f); fclose(f); } f = fopen("test.txt","wt"); if (f) { fprintf(f,"test\n\n\n"); fwrite("test\n\n\n",1,7,f); fclose(f); } return 0; } Using MinGW 3.4.2 on WinXP gives: 2006-07-12 00:23 14 test.bin 2006-07-12 00:23 20 test.txt The text file is 6 bytes larger, as expected. Note that if same source is run on Linux, the result will be: -rw-r--r-- 1 pwm pwm 14 2006-07-12 00:25 test.txt -rw-r--r-- 1 pwm pwm 14 2006-07-12 00:25 test.bin Same size as expected, since the text format uses a single-character newline sequence on unix systems. Both fprintf() and fwrite() will be affected by file opening mode when using MSDOS or Windows compiler. /Per W On Tue, 11 Jul 2006, Hungry Mind wrote: > Yes, you're right...I got the same results on Windows...Are you using it > too? > > > > 2006/7/8, Farzan Hajian <far...@ho...>: > > > > hi, > > > > I've noticed that fwrite() writes data in binary format and fprintf() > > writes data in text format regardless to the mode I use in fopen() to > > open the file. > > In this situation, what the mode argument of fopen() readlly does???? > > I've examined this, with DEV-C++ and Digital Mars compilers and both > > have produced a same result. > > > > Thanx, > > > > -- > > Using Opera's revolutionary e-mail client: http://www.opera.com/mail/ > > > > > > Using Tomcat but need to do more? Need to support web services, security? > > Get stuff done quickly with pre-integrated technology to make your job > > easier > > Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo > > http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642 > > _______________________________________________ > > Dev-cpp-users mailing list > > Dev...@li... > > TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm > > https://lists.sourceforge.net/lists/listinfo/dev-cpp-users > > > |