cowjam
1
I'm reading characters in from a web site, putting them in a an array of chars, then converting it into an integer (it's always an integer).
Whatever the actual number the result comes back as 2289.
This is the relevant code snippet:
char bar[5] = "";
byte foo=0;
char tmp = client.read();
while (tmp != '\n') { //line break signifies end of number
bar[foo] = tmp;
tmp = client.read();
foo++;
}
curUzr = int(bar);
system
2
That's probably the correct value for the address of your buffer
Have you tried 'atoi'?
cowjam
3
How do I get the integer value of the string?
system
4
you haven't got a string until you terminate it.
cowjam
5
Oh. I've added , but it still doesn't work (value has changed though, it's nw 2287). What have I missed?
char bar[5] = "";
byte foo=0;
char tmp = client.read();
while (tmp != '\n') { //line break signifies end of number
bar[foo] = tmp;
tmp = client.read();
foo++;
}
char[foo]='\0';
curUzr = int(bar);
cowjam
6
I've just spotted your mention of atoi. What's that?
YES! That's done it. Thank you AWOL 