473,386 Members | 1,598 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Outputting text to a file

Hi,

I'm creating simple logging function in my server application but i've come
to a little problem. I use fopen and fprintf to open and print to that file
and after the application quits fclose ofcourse but the data get's only
written when i use fclose, i need something so it gets written to the file
directly because otherwise the logging won't have much effect because i want
to run the program for long times. Is there any function to flush the buffer
to the file?

Thanks in Advance,

Robert Mens
Nov 14 '05 #1
6 1913
Robert <R.****@hetnet.nl> scribbled the following:
Hi, I'm creating simple logging function in my server application but i've come
to a little problem. I use fopen and fprintf to open and print to that file
and after the application quits fclose ofcourse but the data get's only
written when i use fclose, i need something so it gets written to the file
directly because otherwise the logging won't have much effect because i want
to run the program for long times. Is there any function to flush the buffer
to the file?


Try fflush().

--
/-- Joona Palaste (pa*****@cc.helsinki.fi) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"Bad things only happen to scoundrels."
- Moominmamma
Nov 14 '05 #2
Robert <R.****@hetnet.nl> scribbled the following:
Hi, I'm creating simple logging function in my server application but i've come
to a little problem. I use fopen and fprintf to open and print to that file
and after the application quits fclose ofcourse but the data get's only
written when i use fclose, i need something so it gets written to the file
directly because otherwise the logging won't have much effect because i want
to run the program for long times. Is there any function to flush the buffer
to the file?


Try fflush().

--
/-- Joona Palaste (pa*****@cc.helsinki.fi) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"Bad things only happen to scoundrels."
- Moominmamma
Nov 14 '05 #3
Robert wrote:
Hi,

I'm creating simple logging function in my server application but i've come
to a little problem. I use fopen and fprintf to open and print to that file
and after the application quits fclose ofcourse but the data get's only
written when i use fclose, i need something so it gets written to the file
directly because otherwise the logging won't have much effect because i want
to run the program for long times. Is there any function to flush the buffer
to the file?


Surprisingly, it's called fflush().
Nov 14 '05 #4
Robert wrote:
Hi,

I'm creating simple logging function in my server application but i've come
to a little problem. I use fopen and fprintf to open and print to that file
and after the application quits fclose ofcourse but the data get's only
written when i use fclose, i need something so it gets written to the file
directly because otherwise the logging won't have much effect because i want
to run the program for long times. Is there any function to flush the buffer
to the file?


Surprisingly, it's called fflush().
Nov 14 '05 #5
In <c5**********@oravannahka.helsinki.fi> Joona I Palaste <pa*****@cc.helsinki.fi> writes:
Robert <R.****@hetnet.nl> scribbled the following:
Hi,

I'm creating simple logging function in my server application but i've come
to a little problem. I use fopen and fprintf to open and print to that file
and after the application quits fclose ofcourse but the data get's only
written when i use fclose, i need something so it gets written to the file
directly because otherwise the logging won't have much effect because i want
to run the program for long times. Is there any function to flush the buffer
to the file?


Try fflush().


If it doesn't have the desired effect (the output is still buffered by
the OS, even if it left your program), close the file after logging each
item and reopen it in append mode before logging a new item. With some
network file systems this may be your only chance of forcing the output to
its final destination (short of using non-standard library calls).

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
Nov 14 '05 #6
In <c5**********@oravannahka.helsinki.fi> Joona I Palaste <pa*****@cc.helsinki.fi> writes:
Robert <R.****@hetnet.nl> scribbled the following:
Hi,

I'm creating simple logging function in my server application but i've come
to a little problem. I use fopen and fprintf to open and print to that file
and after the application quits fclose ofcourse but the data get's only
written when i use fclose, i need something so it gets written to the file
directly because otherwise the logging won't have much effect because i want
to run the program for long times. Is there any function to flush the buffer
to the file?


Try fflush().


If it doesn't have the desired effect (the output is still buffered by
the OS, even if it left your program), close the file after logging each
item and reopen it in append mode before logging a new item. With some
network file systems this may be your only chance of forcing the output to
its final destination (short of using non-standard library calls).

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
Nov 14 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Jonathan | last post by:
I have a client solution that requires data and associated files to be stored with data in a database. As such, I have a situation where JPEG thumbnails/images that are stored as BLOBs (image...
5
by: Andrei Pociu | last post by:
I have a major doubt about outputting text in ASP .NET when using code behind. I know most of the output you gain from a code behind file (.aspx.cs) is outputted to the Webform (.aspx) using...
4
by: JenHu | last post by:
I have a vb.net application, which read the text file line by line and write into SQL server tables. The text file contains the employees' bank account number and all other information. The way...
5
by: Ash Phillips | last post by:
Ok, I'm not sure how I can explain this but here goes. I have this program that uses a ListView for entries. What I have the program doing is taking all the items from the listview, and writing...
3
by: runner7 | last post by:
This is a question about outputting pure XML from PHP, such as to a request object in an AJAX application. I would suppose that all I have to do in my script is to add the line before any other...
4
by: Peter Nimmo | last post by:
Hi, I am writting a windows application that I want to be able to act as if it where a Console application in certain circumstances, such as error logging. Whilst I have nearly got it, it...
5
by: phong.lee | last post by:
Hello all, I was wondering if someone can assist me in outputting 6 reports into a pdf file? I created a macro that generates the 6 reports and right now it's saved as a snapshot on my drive. ...
3
by: mohaakilla51 | last post by:
Alright guys, I am working on a flashcard script... Previously I had it so that it onlty had predefined categories. People were complaining, so now I am trying to make it to where it reads...
12
by: billelev | last post by:
This is probably a very easy question to answer: I have been outputting some text to a message box, similar to the following: strOutput = "---" & Chr(10) & Chr(10) strOutput = strOutput &...
3
by: Ellie | last post by:
I have a VB6 program upgraded to vb.net and I need to use the printline function to write to a text file but I need certain characters in bold. Would anyone be able to tell me how to do this, if...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.