|
-
April 30th, 2004, 10:44 AM
#1
fprintf question
im curious as to what conditions would make fprintf not work
i have a valid file ptr, i have opened the file with fopen and "w"
and the code before and after my fprintf statement works
it just wont write to the file (the file remains empty)
the file in question is just a command line argument that gets open so the permissions are fine as well
any thoughts
-
April 30th, 2004, 10:52 AM
#2
Some code would be nice... At the very least your fprintf line and the variables it uses.
-
April 30th, 2004, 11:32 AM
#3
Without code, I have to take a guess, but guess I will:
1) Is fprintf returning an error code?
2) Is it possible that you still have the file open and the application paused (or blocked or somehow waiting) at the point at which you are manually checking through another window to see what contents it has??
Like the Win32 counterparts, the C Runtime stream routines implement file-buffering by default, so if you REALLY need to see the output immediately after an 'fprintf', you need to make an "fflush(fp)" call to force the data out to disk.
In a performance-oriented application, I would NOT recommend calling fflush() after every fprintf/fwrite-type call.
The other approach is using _setvbuf() to turn off buffering for the stream, but I would only recommend doing this if you *really* need to be able to monitor the output as it comes out.
Cheers!
-
April 30th, 2004, 01:52 PM
#4
i do not mind posting code but i have a lot of it
basically let me give you a quick sumation of what i am doing
i have a server program that fork and exec's a client program
using FIFO's i read a command from a file in the client
i pass the info to the server
the server process's the command and sends a response
this response is what i cannot seem to write to a logfile
i use for example
fprintf(fptr, "just print darn you %s\n", response);
and nothing happens
if i put say a printf b4 and after the fprintf both of those print to the screen
but the file remains empty
what you said about waiting does make sense but...
why would it need to wait if the printf b4 and after it works just fine
-
April 30th, 2004, 01:53 PM
#5
this is on unix using c btw
i am just perplexed as to why it doesnt work
-
April 30th, 2004, 01:59 PM
#6
Un*x also buffers the stream I/O routines, so my comments above still apply.
The reason your printf's work is they go to the console whereas your fprintf goes to a completely different stream. Throw in an fflush(fptr) statement and see if it appears.
-
April 30th, 2004, 02:08 PM
#7
leeND you are a genious
amidst my chaos i would of never considered to just flush
but yes it works like a champ
thank you
rock
if can figure out how to rate you i would and will
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|