String to int

Hy

I got a problem with the atoi() command. Sometimes it does work and sometimes not... example I do process 360 values which i get through the serial. The first column isn't a problem but as you can see in the second sometimes a "-" sign appears and the value is completely wrong. Why does this happen?

217,31515
218,31721
219,31940
220,32172
221,32417
222,32676
223,-32587
224,-32299
225,-31995
226,-31676
227,-31340
228,-30920
229,-31935
230,32653
231,31767
232,30937
233,30158
234,29425
235,28737

Thx Andy

Why does this happen?

Could be bad code, or then again tould be something else. Have you sacrificed a chicken lately to keep things in balance?

The largest number an int can hold is 32767, if that answers your question. Trying to go larger turns on the sign bit and it becomes negative.

strtol() will handle all of the values in your example. See http://www.nongnu.org/avr-libc/user-manual/group__avr__stdlib.html#gaf8ce3b8dae3d45c34c3b172de503f7b3

[quote author=Nick Gammon link=topic=54462.msg389651#msg389651 date=1299374817] The largest number an int can hold is 32767, if that answers your question. Trying to go larger turns on the sign bit and it becomes negative. [/quote]

How could I forget that of course that was the mistake! Thx a lot!

Andy