View previous topic :: View next topic |
Author |
Message |
dbotkin
Joined: 08 Sep 2003 Posts: 197 Location: Omaha NE USA
|
atoi() question |
Posted: Fri May 08, 2009 12:56 pm |
|
|
From the CCS C manual:
Quote: | Converts the string passed to the function into an int representation. Accepts both decimal and hexadecimal argument. |
It seems to work fine with decimal strings, but not hex. If I give it a string containing hex digits (like FF) it returns 0. Anyone know any different? |
|
|
Steve H Guest
|
|
Posted: Fri May 08, 2009 1:32 pm |
|
|
The function is 'inspectable' look at the include header file.
As I recall the HEX has to be in C notation.
e.g. :
"5F" will not work
"0x5F" will work
HTH - Steve H. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
|
Guest
|
|
Posted: Mon May 11, 2009 1:17 pm |
|
|
Oh wow - I went looking for atoi() myself today for another project and only the prototype is on the stdlib.h file now (V4.xxx) - the full function used to be in version 3x.
I thought I was losing my mind - as I could remember seeing it!
No matter - just google atoi() and you will find out how it is done or to use as a base for your own function as PCM suggested....
It is a typical C function - very compact and efficient....
Steve H. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon May 11, 2009 1:40 pm |
|
|
Quote: | only the prototype is on the stdlib.h file now (V4.xxx) |
I looked in stdlib.h in vs. 4.092 and the full source is in there.
It starts at line 429. It looks like this:
Code: | signed int atoi(char *s)
{
signed int result;
unsigned int sign, base, index;
char c; |
|
|
|
Guest
|
|
Posted: Mon May 11, 2009 10:04 pm |
|
|
Oh - so I am loosing my mind! I just needed to look farther down! You are right the atoi() source is still 'Inspectale'
:-)
Thanks for pointing that out...
Steve H. |
|
|
|