Linux Help
guides forums blogs
Home Desktops Distributions ISO Images Logos Newbies Reviews Software Support & Resources Linuxhelp Wiki

Welcome Guest ( Log In | Register )



Advanced DNS Management
New ZoneEdit. New Managment.

FREE DNS Is Back

Sign Up Now
 
Reply to this topicStart new topic
> Terminal Not Recognized In C Program Output
Riddley
post Aug 18 2003, 07:07 PM
Post #1


Whats this Lie-nix Thing?
*

Group: Members
Posts: 4
Joined: 18-April 03
Member No.: 689



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
Go to the top of the page
 
+Quote Post
michaelk
post Aug 18 2003, 08:33 PM
Post #2


Its GNU/Linuxhelp.net
*******

Group: Support Specialist
Posts: 1,797
Joined: 23-January 03
Member No.: 360



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);
Go to the top of the page
 
+Quote Post
Riddley
post Aug 19 2003, 10:27 AM
Post #3


Whats this Lie-nix Thing?
*

Group: Members
Posts: 4
Joined: 18-April 03
Member No.: 689



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
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



RSS Lo-Fi Version Time is now: 19th October 2017 - 06:27 PM