LinuxQuestions.org
Review your favorite Linux distribution.
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
 
LinkBack Search this Thread
Old 12-03-2002, 08:16 AM   #1
JStew
Member
 
Registered: Oct 2002
Location: North Atlanta
Distribution: LFS
Posts: 229

Rep: Reputation: 30
Converting integer types...


In class we are taking input from the user as:

printf("Please enter an integer: ");
scanf("%d", &integer);

we would like to print out this integer in different forms like:

%o
%i
%x ... and so on...

isnt there a function that will change an integer into an octal, hexadecimal and so forth?
 
Old 12-03-2002, 08:22 AM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 39,854

Rep: Reputation: 1121Reputation: 1121Reputation: 1121Reputation: 1121Reputation: 1121Reputation: 1121Reputation: 1121Reputation: 1121Reputation: 1121
well you can just use the equivalent printf formatting strings can't you?

Code:
printf("%d\n", integer);
printf("%o\n", integer);
printf("%x\n", integer);
btw. no more homework questions pls. i presme you're the guy i was talking to the other day in irc?

Last edited by acid_kewpie; 12-03-2002 at 08:29 AM.
 
Old 12-03-2002, 08:41 AM   #3
JStew
Member
 
Registered: Oct 2002
Location: North Atlanta
Distribution: LFS
Posts: 229

Original Poster
Rep: Reputation: 30
Well... thanks for the answer but, i messed up, i phrased the question wrong but never mind--- i kinda fig'd out what i was trying to do...

yeah it is me TheJStew... heh

why no more homework questions?
 
Old 12-03-2002, 08:53 AM   #4
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 39,854

Rep: Reputation: 1121Reputation: 1121Reputation: 1121Reputation: 1121Reputation: 1121Reputation: 1121Reputation: 1121Reputation: 1121Reputation: 1121
if you're trying to convert it to another variable you'd want sprintf... anyway...
 
  


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
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
HEELLP ~~ Converting an integer minute into time, Rounding off a double ~~ HELLP Mistro116@yahoo.com Programming 5 10-04-2005 11:51 AM
Converting types Ephracis Programming 10 12-14-2004 04:15 PM
Integer To a String in C Bean101 Programming 2 05-27-2004 04:46 AM
converting integer value to hexadecimal string in C - any suggestions?? woodywellhung Programming 3 04-24-2004 05:27 PM
Converting filesystem types cyris Linux - General 2 04-11-2003 01:37 PM


All times are GMT -5. The time now is 08:46 AM.

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
Open Source Consulting | Domain Registration