|
From: Ioannis V. <no...@ya...> - 2001-09-04 16:36:10
|
> -----Original Message-----
> From: dev...@li...=20
> [mailto:dev...@li...] On Behalf=20
> Of Michael Codadeen
> Sent: Tuesday, September 04, 2001 9:49 AM
> To: dev...@li...
> Subject: RE: [Dev-C++] how to use strings
>=20
>=20
> Hi,
>=20
> Did you get the fprintf to work because I am still having trouble.
>=20
> I have also tried it at work on a HPUX 10.20 aCC compiler but neither=20
> version works for reading from a file.
>=20
> fprintf (stdout, "%s", fhandle);
> fprintf (stdout, "%s", *fhandle);
>=20
> Note, the second version works on the Dev C++ compiler but=20
> reads the first=20
> line only.
fprintf() does NOT read from a file, it *writes* to the file.
An example:
FILE *fp=3Dfopen("/usr/tony/test.txt", w");
...
fprintf(fp, "This is written to the file.");
fprintf(fp, "A number %d\n\n", 7);
/* Do what you have to do */
fclose(fp);
If you want the data to be written immediately to the file after one
fprintf(), you can flush the cache buffer:
fflush(fp); /* It flushes the file buffer. All data are written to the
disk */
>=20
> And yes, I agree there are many ways to move the file pointer=20
> and that=20
> seeking to the end of a string is bad strategy. I was just=20
> trying to get the=20
> thing to read from a file using fprintf().
I know, hat's why it did not work, since fprintf() is for *writing* to
a stream. For example you can write to the monitor:
fprintf(stdout, "Hello new stream world!\n");
>=20
> Michael
Ioannis
* Ioannis Vranos
* Programming pages: http://www.noicys.f2s.com
* Alternative URL: http://run.to/noicys
|