CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

getting digits out of an int

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Mattr0



Joined: 27 Mar 2005
Posts: 30

View user's profile Send private message Visit poster's website

getting digits out of an int
PostPosted: Sun Mar 27, 2005 2:45 pm     Reply with quote

How can I get the digits out of an interger

ex

if a = 255 then I want to, b = 2, c = 5, d = 5. In pic basic you could just do

b = a dig 0

is there a command like this in c or how would I do such a task
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Sun Mar 27, 2005 4:21 pm     Reply with quote

convert it to a string. look at sprintf or search the forum for more ideas.
Guest








PostPosted: Mon Mar 28, 2005 10:24 am     Reply with quote

If you want to do it w/o a function, i found this handy little function in the program i'm working on. For my purposes, it only works on a number 99 or smaller, but you can build on it.

Code:

// need a buff of size 2
// Preconditions: mybuff points to an int of less than 100.
void int_to_string_conv(unsigned int this_int, char *mybuff)
{
    mybuff[0] = (this_int / 10) + 0x30;
    mybuff[1] = (this_int % 10) + 0x30;
}
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Mon Mar 28, 2005 10:27 am     Reply with quote

Anonymous wrote:
If you want to do it w/o a function, i found this handy little function in the program i'm working on. For my purposes, it only works on a number 99 or smaller, but you can build on it.

Code:

// need a buff of size 2
// Preconditions: mybuff points to an int of less than 100.
void int_to_string_conv(unsigned int this_int, char *mybuff)
{
    mybuff[0] = (this_int / 10) + 0x30;
    mybuff[1] = (this_int % 10) + 0x30;
}


Wouldn't this still be a function Very Happy
Guest








PostPosted: Tue Mar 29, 2005 12:49 pm     Reply with quote

Mark wrote:
Anonymous wrote:


Wouldn't this still be a function Very Happy


oops, i meant a library function Rolling Eyes
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group