View previous topic :: View next topic |
Author |
Message |
Jody
Joined: 08 Sep 2006 Posts: 182
|
AtoI going wrong only for 'D'??? |
Posted: Wed Nov 16, 2011 7:38 am |
|
|
Hello,
compiler version 4.119
Pic: 18F8722
What I have:
Code: |
eeprom_data1[0] = string[i];
eeprom_data1[1] = 0x0D;
data1 = atoi(eeprom_data1); //first byte
|
string I filled with: "D"
and after the atoi data1 is 0...??
When I do this with A or B or 9 or whatever things do like I want.
What am I doing wrong???
Regards,
Jody |
|
|
SherpaDoug
Joined: 07 Sep 2003 Posts: 1640 Location: Cape Cod Mass USA
|
|
Posted: Wed Nov 16, 2011 8:07 am |
|
|
I would have expected atoi() of 9, A, B, or D to return zero. As printed none of them represent a number.
Just what were you expecting the numerical value of carriage return to be? _________________ The search for better is endless. Instead simply find very good and get the job done. |
|
|
Jody
Joined: 08 Sep 2006 Posts: 182
|
|
Posted: Wed Nov 16, 2011 8:21 am |
|
|
I thought that for a AtoI function the string has to be ended with a 0x0d.
And I expected the integer value of the value from the string... |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19544
|
|
Posted: Wed Nov 16, 2011 8:47 am |
|
|
Manual - Quote:
"ivalue = atoi(string)
string is a pointer to a null terminated string of characters."
_Null terminated_.
Second point, 1, does not equal '1'.
Third, to convert hex values, the string has to include the format characters to say 'hex value', otherwise how would it ever tell the difference between '11' decimal, and '11' hex?.
Code: |
char string[10];
int i;
strcpy(string,"0x11");
x=atoi(string);
|
Best Wishes |
|
|
|