The function atoi (and sscanf, atof etc), all appear to have the same (unlikely) problem: they don't read the number 5. Yes, I realize that this seems very unlikely.
I am using uVision version 4.21 for the LPC3250
Here are the pertinent lines of code:
#include <stdio.h> #include <stdlib.h> #include <string.h>
char * cPtr; static char buff[512]; int i1 = 0, i2 = 0, i3 = 0;
buff[0] = “6”; buff[1] = “ ”; buff[2] = “5”; buff[3] = “ ”; buff[4] = “7”; buff[5] = “ ”; buff[6] = 0;
cPtr = strtok(buff," ,."); i1 = atoi(cPtr); cPtr = strtok(NULL," ,."); i2 = atoi(cPtr); cPtr = strtok(NULL," ,."); i3 = atoi(cPtr);
The result is: i1 = 6 i2 = 0 i3 = 7
What I expected was: i1 = 6 i2 = 5 i3 = 7
I have tried many variants of this program. I also tried the same with sscanf. Always misses the 5, no matter what position the 5 appears in.
Has anyone any ideas why this is happening?
Has anyone seen the same problem?
The code shown in my first post was a little jumbled. So here it is again:
Hope it comes out right this time.
My questions are (still): Has anyone any ideas why this is happening? Has anyone seen the same problem?
Still a a bit of a jumble, huh?
www.danlhenry.com/.../keil_code.png
Don't just hope - use the 'Preview' to confirm it!
static char buff[512]; buff[0] = “6”; buff[1] = “ ”; buff[2] = “5”; buff[3] = “ ”; buff[4] = “7”; buff[5] = “ ”; buff[6] = 0;
Care to tell us why you are assigning strings to the individual positions of your character array?
A character is given with single quotes: '5'. A string is given with double quotes: "5".
By the way - how come your post are using prettified, typographic quotes?