• Post Reply Bookmark Topic Watch Topic
  • New Topic

Linux newbie quesiton  RSS feed

 
Shyam Purkayastha
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all
I have a silly problem and as i am new to linux programming i am quite baffeled
I have written a simple hello world program in c
,compiled with gcc and ran it.IT is not showing any errors in complation or run stage but the output "Hello World" is not displaying.
Does it has anything to do with I/O redirection or something else.Please advise
thanks
shyam
 
Jonas Isberg
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't forget to out a new line character last in your output. Try outputting "Hello World\n" instead of "Hello World". If that doesn't help, please post your code. Good luck!
 
Layne Lund
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you please provide more detail? For example, post the code and the exact command line you use to compile and run it. Also, a listing of the output would be nice. You can easily copy and paste it from the console window (assuming you are using a console window and not some IDE). These will help us more accurately diagnose the problem.
Keep coding!
Layne
 
Tim Holloway
Saloon Keeper
Posts: 18800
74
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If it makes you feel better, I'd been working with C/C++ for about 15 years and ran into the same thing, though it's been so long that I forget what the problem was.
I think it may have been lack of the terminating "\n", but I'm not positive. All I remember is that Linux wasn't as co-operative in getting the output to the console.
If all else fails, add a "flush(stdout);" statement after the prints. Supposedly encountering an "\n" or end of program should automatically invoke the flush() function, but, as I said, in Linux I don't think this is the case.
Hint: when posting code, use the UBB CODE feature (click the button labelled "CODE". It will insert brackets that keep your indentation from getting all mangled. Like so:
 
Shyam Purkayastha
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank u all for the advice
Adding \n has really worked
however when i write
printf("Hello \n World");
only Hello is displayed
This thing is pretty werid and dosent happen in turbo c or any other windows based c compiler
Why is it so?
thanks a lot abain
shyam
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!