/var/www/restricted/ssh/stm32/www/stm32circle/ STM CircleOS forum / Integer to String conversion

Username:     
Password:     
             

Forum

# 1   2010-07-16 16:55:46 Integer to String conversion

darkhedie
New member
Registered: 2010-07-14
Posts: 1

Integer to String conversion

Hello

Im a new user of the Forum and of a Primer2


My Question... How can i convert an Integer to a String?

Thanks smile

Offline

 

# 2   2010-07-19 04:54:31 Integer to String conversion

repzak
Member
Registered: 2008-03-05
Posts: 170

Re: Integer to String conversion

Hello,

You could use printf function

Kasper

Offline

 

# 3   2010-07-19 17:28:04 Integer to String conversion

jC_Omega
New member
From: Vichy - France
Registered: 2010-07-14
Posts: 8
Website

Re: Integer to String conversion

Hi,


Or, you can add this code.

This function is much more economical in memory that the function "printf" (just to make a conversion)

Code:

/************************************************************************
 Function: Int2Str(char *pStr, unsigned int value, int charCount)
 
 Overview: Converts integer value to string to be displayed in the
           edit boxes that displays the RGB values.
             
 Input: pStr - pointer to the string holder of the value to be displayed
         value - the integer value that will be converted.
         charCount - the number of characters that was converted.

 Output: none
************************************************************************/
void Int2Str(char *pStr, unsigned int value, int charCount)
{

    // this implements sprintf(strVal, "%d", temp); faster
    // note that this is just for values >= 0, while sprintf covers negative values.
    // this also does not check if the pStr pointer points to a valid allocated space.
    // caller should make sure it is allocated.
    // point to the end of the array
    pStr = pStr + (charCount - 1);

    // convert the value to string starting from the ones, then tens, then hundreds etc...
    do
    {
        *pStr-- = (value % 10) + '0';
        value /= 10;
    } while(charCount--);
}

jC_Omega

Offline

 

# 4   2010-07-20 01:13:50 Integer to String conversion

wincent
Member
Registered: 2008-06-23
Posts: 19
Website

Re: Integer to String conversion

Hello,

use int2str(), http://www.stm32circle.com/circleos_doc … c34b513886

Sincerely yours,

wincent

Offline

 

Board footer