LinuxQuestions.org
Help answer threads with 0 replies.
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 04-06-2008, 11:55 AM   #1
snowman81
Member
 
Registered: Aug 2006
Location: Michigan
Distribution: Ubuntu
Posts: 225

Rep: Reputation: 30
Help with printf command in C program


I have a C program that I modified to suit me but I can't figure out the printf command.
Code:
#include <stdio.h>

int main()
{
int float1, kelvin, celsius;

//printf("Fahrenheit to Celsius Conversion\n\n");

scanf("%d", &celsius);

kelvin = celsius + 273;

printf("\n d% ", kelvin);

return 0;
}
Can anyone point me in the right direction?
 
Old 04-06-2008, 12:05 PM   #2
Nylex
LQ Addict
 
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,464

Rep: Reputation: Disabled
What exactly are you having problems with?
 
Old 04-06-2008, 12:15 PM   #3
snowman81
Member
 
Registered: Aug 2006
Location: Michigan
Distribution: Ubuntu
Posts: 225

Original Poster
Rep: Reputation: 30
In the above program, the printf command only returns the letter "d". I want it to return the variable "kelvin". Just to clarify, not the word "kelvin" but the value of it.
 
Old 04-06-2008, 12:19 PM   #4
Nylex
LQ Addict
 
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,464

Rep: Reputation: Disabled
Ah, it should be "%d", rather than "d%". "%d" is a specifier, see this for more info.
 
Old 04-06-2008, 12:26 PM   #5
snowman81
Member
 
Registered: Aug 2006
Location: Michigan
Distribution: Ubuntu
Posts: 225

Original Poster
Rep: Reputation: 30
Perfect, thanks.
 
Old 04-07-2008, 03:25 PM   #6
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,395
Blog Entries: 2

Rep: Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903
Actually, since your variables are floating point types, you probably want to use "%e", "%f", or "%g" for the format conversion specifier.
--- rod.
 
Old 04-07-2008, 06:46 PM   #7
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian
Posts: 2,517

Rep: Reputation: 855Reputation: 855Reputation: 855Reputation: 855Reputation: 855Reputation: 855Reputation: 855
Actually they are all ints, though you could be forgiven for not realizing "float1" is an integer
 
Old 04-07-2008, 09:28 PM   #8
Dan04
Member
 
Registered: Jun 2006
Location: Texas
Distribution: Ubuntu
Posts: 207

Rep: Reputation: 37
Quote:
Originally Posted by ntubski View Post
Actually they are all ints, though you could be forgiven for not realizing "float1" is an integer
And he's not even using it.
 
Old 04-08-2008, 01:12 AM   #9
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,395
Blog Entries: 2

Rep: Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903
My bad. I saw 'float' and jumped to the wrong conclusion without looking closely enough.
--- rod.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
How to use c++ to use a command line program jboss1995 Programming 4 04-05-2008 11:22 PM
executing a command as part of printf... thatbloke Linux - Newbie 6 05-06-2004 05:15 PM
Viewing program messages when program isn't run from command line? Locura Linux - Software 1 09-27-2003 09:19 AM
How could a program crash between 2 printf() 's? paul76 Programming 12 09-11-2003 01:17 PM
printf new_user10 Programming 3 09-10-2003 12:12 AM


All times are GMT -5. The time now is 12:32 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration