Help - Search - Members - Calendar
Full Version: Terminal Not Recognized In C Program Output
Linuxhelp > Support > Technical Support
Riddley
This short C program compiles and runs without error

--------------------------------------------
#include <stdio.h>

int main(){

FILE *fp;
fp = fopen("hi.out","w");

fprintf(fp,"hi");
printf("hi there");
fprintf(stdout,"hi there again");

return 0;
}
---------------------------------------------

The hi.out file gets created and contains the characters "hi", however "hi there" and
"hi there again" never appears on the screen. Is there something I must set in Linux
to properly redirect the these outputs?

Thanks,
Louise
michaelk
It works as is for me and I don't see why it shouldn't work. What linux distro and version of gcc do you have?

I might add a LF i.e n to each of the output lines and also close the file before exiting.

fclose(fp);
Riddley
Thanks Michael!

The "n " is what made the difference.

I wonder if this had to do with the way Linux handles the terminal promt - I'm surprised the program didn't work as is.

Btw, I am running

Linux vivian 2.4.18-14 #1 Wed Sep 4 13:35:50 EDT 2002 i686 i686 i386 GNU/Linux

which I believe is RedHat 8.0

and

i686-pc-linux-gnu-gcc-3.3

which I installed myself. Therein could lie the problem.

Louise
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2017 Invision Power Services, Inc.