C Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesC Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old October 1st, 2012, 11:24 AM
LightningBlade LightningBlade is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2012
Posts: 3 LightningBlade User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 32 m 45 sec
Reputation Power: 0
Post Simple printf statment not working

I have not been programming in C very long, but for some reason I can't even get a simple printf statement to work, even though it looks identical to another statement that does work.

Code:
#include <stdio.h>

int main() {
printf("Hi\n");
return 0;
}


When I compile I get no error (compiling on Linux with gcc).
When I run it there is no output at all. It returns to the next line waiting for another command (back to the ~$ prompt)

Any ideas as to what I'm doing wrong? I can't figure it out.

Reply With Quote
  #2  
Old October 1st, 2012, 11:34 AM
b49P23TIvg's Avatar
b49P23TIvg b49P23TIvg is offline
Contributing User
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Aug 2011
Posts: 3,345 b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 3 Days 6 h 47 m 59 sec
Reputation Power: 383
Code:
$ cat > c.c
#include <stdio.h>

int main() {
printf("Hi\n");
return 0;
}
$ gcc c.c
$ ./a.out
Hi
$


by the way, I recommend puts("Hi") rather than the long winded and inefficient printf("this string has to be scanned for format specifiers\n")
Comments on this post
LightningBlade agrees!
__________________
[code]Code tags[/code] are essential for python code!

Reply With Quote
  #3  
Old October 1st, 2012, 11:41 AM
LightningBlade LightningBlade is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2012
Posts: 3 LightningBlade User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 32 m 45 sec
Reputation Power: 0
Quote:
Originally Posted by b49P23TIvg
by the way, I recommend puts("Hi") rather than the long winded and inefficient printf("this string has to be scanned for format specifiers\n")

I'm actually trying to test an output for another program I'm writing, and I was putting it into a separate program (the other one won't compile yet) and it is a little more complex than just "Hi", but for some reason I couldn't get it to print anything, and so I tried several different things, and even "Hi" wouldn't print. So, that's when I came with the question.

--Edit--
I tried compiling it exactly like you did ($ gcc c.c) and it works. When I try compiling it like this ($ gcc -o test c.c) it doesn't. Is this normal, or do I have to compile to a.out all the time?

Reply With Quote
  #4  
Old October 1st, 2012, 11:47 AM
b49P23TIvg's Avatar
b49P23TIvg b49P23TIvg is offline
Contributing User
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Aug 2011
Posts: 3,345 b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 3 Days 6 h 47 m 59 sec
Reputation Power: 383
test is ...


$ which test
/usr/bin/test


Run your program with

./test

or, worse, change your PATH variable.
Comments on this post
Lux Perpetua agrees: I (and probably a lot of people) have made this exact mistake in the past.

Reply With Quote
  #5  
Old October 1st, 2012, 11:52 AM
LightningBlade LightningBlade is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2012
Posts: 3 LightningBlade User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 32 m 45 sec
Reputation Power: 0
Thanks for your help.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesC Programming > Simple printf statment not working

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap