Reply by cfbsoftware1 August 31, 20102010-08-31
--- In l..., Pete Vidler wrote:
>
> Some of the solutions posted so far are changing my mind about this.
> Global buffers, no checks or limits on buffer accesses, magic constants,
> etc.
>

I have to agree with you - talk about the 'blind leading the blind'!

Perhaps they suspected that the OP was doing a homework assignment and they wanted to trap him into failing ;-)

Regards,
Chris Burrows

CFB Software
Astrobe: LPC2xxx Oberon-07 Development System
http://www.astrobe.com

An Engineer's Guide to the LPC2100 Series

Reply by Pete Vidler August 31, 20102010-08-31
On 30/08/2010 18:47, nej22uk wrote:
> 42Bastian wrote:
> > But snprintf() is far to heavy for the job he wants to do.
>
> Depends what the complete system is doing - with enough calls the cost
> of the library may be neglible.

In size terms, this is true. If you are also looking at time (and power
consumption), more calls can only make things worse. Most sprintf
implementations that I've encountered are very slow.

More importantly, within the context this operation is trivial to write
yourself at minimum cost in developer time, code size or speed. For a
<= 3 digit temperature, sprintf would just seem lazy to me.

Some of the solutions posted so far are changing my mind about this.
Global buffers, no checks or limits on buffer accesses, magic constants,
etc.

Pete

--
Pete Vidler
Senior Systems Developer,
TTE Systems Ltd

Work: http://www.tte-systems.com
Home: http://petevidler.com
Reply by nej22uk August 30, 20102010-08-30
Hi,

42Bastian wrote:
>
> Am 27.08.2010 08:03, schrieb Laurie Gellatly:
> > Google is amazing. Try using snprintf().
>
> But snprintf() is far to heavy for the job he wants to do.

Depends what the complete system is doing - with enough calls the cost of the library may be neglible.

For a lightweight printf near-compatible formatting library try this:

http://code.google.com/p/format/

(yes, its one of my projects, but it is open source, so this is not a commercial plug :)

> I wonder if itoa() is part of the stdlib or not. If the compiler does not
> complain, it is likely a linker setup problem.

According to my copy of the C99 standard there is no itoa() in the standard library. sprintf() would be the natural choice.

Cheers,
Neil

Reply by Mukund Deshmukh August 29, 20102010-08-29
One issue I see with this, is that it could leave a number of characters
at the beginning of the string uninitialized, depending on the value passed
to it.

You are on dot...
The initialization depends on the use of string. If you don't want leading
zero, then initialize to 0x20 else can be initialized to 0x30.
Warm Regards,
Mukund Deshmukh,
Beta Computronics Pvt Ltd,
10/1, IT Park, Parsodi,
Nagpur -440022, INDIA.

Meet us at -
K2010, Booth No. 12C40, 27th Oct - 3rd Nov 2010, Dseldorf, Germany.

Reply by Michael Anton August 29, 20102010-08-29
One issue I see with this, is that it could leave a number of characters
at the beginning of the string uninitialized, depending on the value passed
to it.

Mike
> -----Original Message-----
> From: l...
> [mailto:l...]On Behalf
> Of Mukund Deshmukh
> Sent: Sunday, August 29, 2010 12:13 AM
> To: l...
> Subject: Re: [lpc2000] Re: keil uVision RVMDK error
> >> I think so too. Can you suggest a simple
>
> void intstr (unsigned short int value)
> {
> unsigned char index1;
> index1 = 5;
> do {
> lcdstr[--index1] = '0' + (value % 10);
> value /= 10;
> } while (value != 0);
>
> lcdstr[5]=0;
> }
>
> value => to be converted to string
> lcdstr => string containing ascii value of digits.
>
> Warm Regards,
> Mukund Deshmukh,
> Beta Computronics Pvt Ltd,
> 10/1, IT Park, Parsodi,
> Nagpur -440022, INDIA.
>
> Meet us at -
> K2010, Booth No. 12C40, 27th Oct - 3rd Nov 2010, Dseldorf, Germany.
>

Reply by Mukund Deshmukh August 29, 20102010-08-29
>> I think so too. Can you suggest a simple

void intstr (unsigned short int value)
{
unsigned char index1;
index1 = 5;
do {
lcdstr[--index1] = '0' + (value % 10);
value /= 10;
} while (value != 0);

lcdstr[5]=0;
}

value => to be converted to string
lcdstr => string containing ascii value of digits.

Warm Regards,
Mukund Deshmukh,
Beta Computronics Pvt Ltd,
10/1, IT Park, Parsodi,
Nagpur -440022, INDIA.

Meet us at -
K2010, Booth No. 12C40, 27th Oct - 3rd Nov 2010, Dseldorf, Germany.

Reply by Donald H August 28, 20102010-08-28
--- In l..., "MAYURESH M" wrote:
>
> I think so too. Can you suggest a simple work around for it? What i am actually doing is, i am calculating temperature using an external sensor. The result is stored in an int variable. I want to display it on the LCD and for that i want to convert it into string so that i can use the lcd_putstring() function. The value will be updated every second.

Brute force don't hurt:

void dec_int_out( UINT dec )
{
UINT temp;

temp = dec/10000;
if( temp>0)
{
ser_out(temp+0x30);
dec -= temp*10000;
}

temp = dec / 1000;
if (temp > 0)
{
ser_out(temp+0x30);
dec -= temp*1000;
}

temp = dec / 100;
ser_out(temp+0x30);
dec -= temp*100;
temp = dec / 10;
ser_out(temp+0x30);
dec -= temp*10;
ser_out(dec+0x30);
}

Reply by bonzadog August 27, 20102010-08-27
I performed an itoa search in Keil Help - there were no entries. atoi
does exit as such but atoll- but returns a long. I wrote a "converted
int to string" myself.

Google is no help on this.

BD

Am 27.08.2010 10:04, schrieb MAYURESH M:
> I'll try what you suggested. I got the same suggestion from 2 more people. Thanks a lot mate.
>
> --- In l..., Pete Vidler wrote:
>>
>> On 27/08/2010 07:50, MAYURESH M wrote:
>>> What i am actually doing is, i am calculating temperature using an
>>> external sensor. The result is stored in an int variable.
>>
>> You just want integer temperature converted to a string? That should be
>> trivial to do manually without snprintf or itoa!
>>
>> Hint 1: Get the least significant decimal digit with "number % 10".
>> Hint 2: Remove the least significant digit with "number /= 10".
>> Hint 3: Make a digit into a character with "digit + '0'".
>> Hint 4: You probably only need 3 digits and a sign...
>> Hint 5: Strings are arrays of char ending in a 0.
>>
>> Sounds like a good interview question to ascertain knowledge of basic C
>> programming.
>>
>> Pete
>>
>> --
>> Pete Vidler
>> Senior Systems Developer,
>> TTE Systems Ltd
>>
>> Work: http://www.tte-systems.com
>> Home: http://petevidler.com
>

Reply by Mukund Deshmukh August 27, 20102010-08-27
>I think so too. Can you suggest a simple
Actually it's very simple.
Divide the int value with 10, take the remainder and add 0x30 to it. Store
the value in a string. Do this for 5 times (Int value max 65xxx) Print the
string.
Done!!
Warm Regards,
Mukund Deshmukh,
Beta Computronics Pvt Ltd,
10/1, IT Park, Parsodi,
Nagpur -440022, INDIA.

Meet us at -
K2010, Booth No. 12C40, 27th Oct - 3rd Nov 2010, Dseldorf, Germany.

Warm Regards,
Mukund Deshmukh,
Beta Computronics Pvt Ltd,
10/1, IT Park, Parsodi,
Nagpur -440022, INDIA.

Meet us at -
K2010, Booth No. 12C40, 27th Oct - 3rd Nov 2010, Dseldorf, Germany.

Reply by MAYURESH M August 27, 20102010-08-27
I'll try what you suggested. I got the same suggestion from 2 more people. Thanks a lot mate.

--- In l..., Pete Vidler wrote:
>
> On 27/08/2010 07:50, MAYURESH M wrote:
> > What i am actually doing is, i am calculating temperature using an
> > external sensor. The result is stored in an int variable.
>
> You just want integer temperature converted to a string? That should be
> trivial to do manually without snprintf or itoa!
>
> Hint 1: Get the least significant decimal digit with "number % 10".
> Hint 2: Remove the least significant digit with "number /= 10".
> Hint 3: Make a digit into a character with "digit + '0'".
> Hint 4: You probably only need 3 digits and a sign...
> Hint 5: Strings are arrays of char ending in a 0.
>
> Sounds like a good interview question to ascertain knowledge of basic C
> programming.
>
> Pete
>
> --
> Pete Vidler
> Senior Systems Developer,
> TTE Systems Ltd
>
> Work: http://www.tte-systems.com
> Home: http://petevidler.com
>