int to char *array[ ].

View: New views
3 Messages — Rating Filter:   Alert me  

int to char *array[ ].

by markus-52 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hello.

I am having problem due to my limited knowledge of C.

I have function readADC wich wil return value in integrer.
Sadly the function LcdStr (wich is from Fandi Gunawan library for nokia 3310 lcd) accepts only char array pointers.

So, i need to make int 123 into char *array[3] = 1, 2, 3

I have been stuck on it for a day and have ran out of ideas. Maybe someone could point me to the right direction or help me figure it out.

Cmc

_______________________________________________
AVR-chat mailing list
AVR-chat@...
http://lists.nongnu.org/mailman/listinfo/avr-chat

Re: int to char *array[ ].

by Daniel O'Connor-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Sun, 4 Oct 2009, markus järve wrote:

> Hello.
>
> I am having problem due to my limited knowledge of C.
>
> I have function readADC wich wil return value in integrer.
> Sadly the function LcdStr (wich is from Fandi Gunawan library for
> nokia 3310 lcd) accepts only char array pointers.
>
> So, i need to make int 123 into char *array[3] = 1, 2, 3
>
> I have been stuck on it for a day and have ran out of ideas. Maybe
> someone could point me to the right direction or help me figure it
> out.
char *array[3];

for (i = 0; i < 3; i++)
        arrary[i] = readADC();

or perhaps..

char *array[3];

for (i = 0; i < 3; i++)
        arrary[i] = readADC() + '0';

--
Daniel O'Connor software and network engineer
for Genesis Software - http://www.gsoft.com.au
"The nice thing about standards is that there
are so many of them to choose from."
  -- Andrew Tanenbaum
GPG Fingerprint - 5596 B766 97C0 0E94 4347 295E E593 DC20 7B3F CE8C


_______________________________________________
AVR-chat mailing list
AVR-chat@...
http://lists.nongnu.org/mailman/listinfo/avr-chat

signature.asc (195 bytes) Download Attachment

Re: int to char *array[ ].

by Piotr Nikiel :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


On Oct 4, 2009, at 1:41 PM, markus järve wrote:

> Hello.
>
> I am having problem due to my limited knowledge of C.
>
> I have function readADC wich wil return value in integrer.
> Sadly the function LcdStr (wich is from Fandi Gunawan library for  
> nokia 3310 lcd) accepts only char array pointers.
>
> So, i need to make int 123 into char *array[3] = 1, 2, 3
>
> I have been stuck on it for a day and have ran out of ideas. Maybe  
> someone could point me to the right direction or help me figure it  
> out.

Don't you need to use integer -> ascii conversion?
Like

char array[4];
snprintf (array, sizeof(array), "%d", readADC());

I set array to be 4 elements length, because snprintf will put  
terminating zero in the last byte, but that shouldn't matter for  
LcdStr, If it accepts char*.

Cheers,
Piotr

_______________________________________________
AVR-chat mailing list
AVR-chat@...
http://lists.nongnu.org/mailman/listinfo/avr-chat