[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[avr-gcc-list] Error converting int to string
From: |
Leo Hendrawan |
Subject: |
[avr-gcc-list] Error converting int to string |
Date: |
Sat, 4 Dec 2004 04:22:41 +0000 (GMT) |
Hello all,
i'm working on my function which parse the ip addr int type variable into
strings. but i have some problem to do the reverese process (make an array
string ended with '\0' from int varible type ip address).
i put my code below...
the desired ip address is: 167.205.67.1,
but when i use AVR studio 4 simulation (i use winavr20040404)
at the line:
itoa(temp,lbuf,10); // the problem is right here
it always make the lower value of ipaddr2[0] to 0, which result the wrong
ip address string: "167.0.67.1"
does anyone have any suggestion why this happens?
best regards,
Leo Hendrawan
//////////////////////////////////
// My code:
//////////////////////////////////
char volatile buffer[20];
char lbuf[3];
unsigned int volatile ipaddr1[2],ipaddr2[2];
void main(void)
{
............
char dot[]=".";
int volatile temp;
ipaddr2[0] = (167<<8) | 205;
ipaddr2[1] = (67<<8) | 1;
temp = ipaddr2[0]>>8;
itoa(temp,lbuf,10); // the problem is right here
strcpy((char*)buffer, lbuf);
strcat((char*)buffer,dot);
clear(lbuf);
temp = ipaddr2[0]&0xff;
itoa(temp,lbuf,10);
strcat((char*)buffer, lbuf);
strcat((char*)buffer,dot);
clear(lbuf);
temp = ipaddr2[1]>>8;
itoa(temp,lbuf,10);
strcat((char*)buffer, lbuf);
strcat((char*)buffer,dot);
clear(lbuf);
temp = ipaddr2[1]&0xff;
itoa(temp,lbuf,10);
strcat((char*)buffer, lbuf);
}
- [avr-gcc-list] Error converting int to string,
Leo Hendrawan <=