read integer from sd card

hi i have a txt file in the sd card

in the txt have a number. it writing 82

but when readed the file from due , serial prints:

56
50

the codes :

minvent = SD.open("minvent.txt");
  if (minvent) {
    while (minvent.available()) {
        Serial.println(minvent.read());
    }
    minvent.close();
  }

i want to get it to a integer variable,

when i write :

int say=0;
 while (minvent.available()) {
        say=minvent.read();
    }

Serial.print(say);

the screen :

10

but my value is 82. can someone help me ?

If you look up the ASCII code for the character '8', you'll find that it is 56 while a '2' is 50. See the pattern?

www.asciitable.com for all the characters.

CrossRoads: www.asciitable.com for all the characters.

crossroads,

thank for information, because i am silly that dont know ascii table !

if i do not know ascii table, i would not buy arduino ok ?

i have a number, sometimes 2 sometimes 3 digits.

i want to read from sd card to integer value.

if is it impossible, i want to a function that converting chr to int, if it runs correctly.

if you have, please tell me, i need it.

there are someones and they are thinking "i am boss of company of arduino" No! we are customers, when we need help, someone must help us. so we are not little customers, we have a factory and we have 90,000 $ investment. but here are someone wants to i waste the money .

No! we are customers, when we need help, someone must help us.

There is no compulsion here for anyone to help you - we are all volunteers.

If you're not willing to put in some effort to solve your problem, you're in the wrong place.

i have a number, sometimes 2 sometimes 3 digits.

How do you know which? Is "32767" to be interpreted as "32" and "767" or "327" and "67"? Do you have commas to separate numbers?

Come on - help us to help you.

Oh, and asking the same question on different parts of the forum is called "cross-posting" (because it makes us very, very cross), and is a fast-track to a forum ban.

hi awol,

i did not know about you are volunteers, sorry for it

i have a txt file in sd, eg. num.txt

in txt file, there are writing a number.

e.g. 8 or 58 or 126

i want to read it to an integer, not in char. when the reading to char, i combine it ( e.g. 58) 5 and 8. and i have problem that, like 586354 or 58123 or 5825 .

i want to learn a correct function for reading to an integer variable. not string not char not float, i want to integer.

sorry for all things

586354 or 58123

Neither of those values will fit in an "int" on one of the eight bit Arduinos. You need to think about "long" or "unsigned long" for those sort of values.

Otherwise, set a variable to zero - let's call it "value". Read an ASCII character, if it is a digit ("isdigit()"), then subtract '0' from it and call it "digit", multiply "value" by ten and add "digit" to it. Go back and read another character. Rinse and repeat. If the character wasn't a digit, then "value" contains your number.

There are other ways, like reading all the number into another string, and using "atoi" or "atol", or . . . plenty of ways of skinning this particular cat.*

  • No cats were harmed in the making of this post.