CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

AtoI going wrong only for 'D'???

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Jody



Joined: 08 Sep 2006
Posts: 182

View user's profile Send private message Send e-mail

AtoI going wrong only for 'D'???
PostPosted: Wed Nov 16, 2011 7:38 am     Reply with quote

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

View user's profile Send private message

PostPosted: Wed Nov 16, 2011 8:07 am     Reply with quote

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

View user's profile Send private message Send e-mail

PostPosted: Wed Nov 16, 2011 8:21 am     Reply with quote

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: 19545

View user's profile Send private message

PostPosted: Wed Nov 16, 2011 8:47 am     Reply with quote

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
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group