reading my sd card and data in sd be as input variable.

im totally newbie, pls help me, i don’t want to do. i already have data in my sd card. which is 89, i want to save it in a variable as int.

here’s my code.:

#include <SPI.h>
#include <SD.h>

File myData;

char a[5],c; // in here i just testing if the data in my sd card are char or int..im loss here.
int b =0;

void setup() {
Serial.begin(9600);
Serial.print("Initializng SD card..");

if (!SD.begin(4)) {      //This opens the communication of CS pin to the Arduino Board and if it is not connected the initialization will failed.
    Serial.println("Initialization failed!");
    return;
  }
  
  Serial.println("Initialization done.");
  
  myData = SD.open("C-B.txt");

if (myData) {
    Serial.println("C-B.txt");
    while (myData.available()) { // If the file is present execute loop until done.
        Serial.write(myData.read()); //Reading the text inside the file
        a[b] = myData;
        
        c = c + a[b];
        b++;
    }
 
  Serial.println("NUmber:");
  Serial.print(c);
  
    myData.close(); //Close the file after opening
  } else { //Display message if it was unsuccessfully opened.
    Serial.println("Error opening test.txt");
  }

}


void loop() {
  // put your main code here, to run repeatedly:

}

epic2big:
im totally newbie, pls help me, i don't want to do. i already have data in my sd card. which is 89, i want to save it in a variable as int.

File is stream

int value = myData.parseInt();

ty..

myData is a file; you can not add a file to an array element like you do here

     a[b] = myData;

Further, once you have read a character, you can not read it again.

Serial.write(myData.read()); //Reading the text inside the file

There are ways around that using e.g. seek, but it's easier to read the character from the file into a variable (below variable ch).

   while (myData.available()) { // If the file is present execute loop until done.
      char ch = myData.read();
      Serial.write(ch); //Reading the text inside the file
      a[b] = ch;
      c = c + a[b];
      b++;
    }

And next you can convert the array a to an integer using the atoi() function.

Some advise
Never use single letter variables as global variables; for this small example like yours it does not matter but if your code grows, you will have a hell of a time finding where they are used.
a could e.g. be renamed to fileData, c could be renamed to value and b could be renamed to cnt or index.

@sterretje, it is much simpler to read a file with Stream timed functions like readBytes or readString or parseInt

Yes, it is; but I found it important to point out the errors in the original code.