LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-10-2011, 11:05 AM   #1
MPRT
Member
 
Registered: Apr 2010
Location: Rio de Janeiro
Distribution: Ubuntu, Fedora, Slackware
Posts: 30

Rep: Reputation: 0
printf is printing to the file


Dear all,

I’d like to share with you a strange behavior I’ve been seen with the printf C language function running in Fedora.
The code opens a file as showed:
descString = fopen( strcat( stringName, “.txt”), “a+” );
There are also some printf functions in the code.
However, instead of the printf functions to print their content at the screen, they’ve been printing them in the file with the descString file descriptor.
Have you ever seen something like that?

To print something to the file I use the fprintf function. I didn't make a mistake to confuse printf with fprintf. I'm sure.

Thanks in advance!
Best regards,
MPRT
 
Old 05-10-2011, 12:37 PM   #2
dwhitney67
Senior Member
 
Registered: Jun 2006
Location: Maryland
Distribution: Kubuntu, Fedora, RHEL
Posts: 1,541

Rep: Reputation: 335Reputation: 335Reputation: 335Reputation: 335
Before the first printf() that prints to a file, check to see if there is an fclose() on the standard-out stream, followed by an fopen() to a file. Something like this:
Code:
#include <stdio.h>

int main()
{
   fclose(stdout);

   FILE* out = fopen("foo.txt", "w+");

   printf("This is a test.\n");   /* output goes to the file */

   fclose(out);

   return 0;
}
 
Old 05-10-2011, 05:34 PM   #3
wtruong
Member
 
Registered: May 2009
Distribution: ubuntu
Posts: 35

Rep: Reputation: 16
Can you post your code?

Are there any freopen's in the code?
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Searching .txt file for (specific) strings and printing them to new file Hb_Kai Linux - General 7 02-18-2010 09:09 AM
BASH - printf printing escape codes even though I have %0b defined DevonB Linux - Newbie 5 12-23-2009 01:42 PM
[SOLVED] Sometimes not getting entire file when printing to a file in SeaMonkey blackhole54 Linux - Software 2 08-06-2009 11:44 PM
Printing a new file over the old file using cat mrobertson Programming 4 07-07-2005 10:18 AM
Printing a file NitzGuy Linux - Newbie 1 07-24-2003 10:03 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:07 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration