Need code to send block of data present in text file of sd card to arduino

Hi.
i need to do two works.

1 Read a text file from sd card and send to arduino so that, 2. I can send those data to other arduino board which is a slave to first arduino

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

char c[32];
int i = 0;
File file;

void setup()
{
  Serial.begin(57600);    //Begin serial communication
  pinMode (10,OUTPUT);    //Set pin 53 as output for SD lib
  if (!SD.begin(9)){     //Check that SD card is initialized
    Serial.println("SD not initialized");
  }
  else {
    Serial.println("SD initialized");
  }
  file = SD.open("logdata.txt");  //Open file
  if(file) {
    Serial.println("File opened");  
    while (file.available()>0) {
      c[i]=file.read();
      i=i+1;
    }
    Serial.print(c);


void loop()
{
  delay(100);
}

I need a code that transfers data from sd card to arduino

Thank you.

Unless your entire file is less than 32 characters long you should probably process the file one character at a time:

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

File file;

void setup() {
  Serial.begin(57600);    //Begin serial communication
  SPI.begin();
  pinMode (10,OUTPUT);
  if (!SD.begin(9)) {     //Check that SD card is initialized
    Serial.println("SD not initialized");
    return;
  }
  else {
    Serial.println("SD initialized");
  }
  file = SD.open("logdata.txt");  //Open file
  if(file) {
    Serial.println("File opened");  
    while (file.available()) {
      char c = file.read();
      Serial.write(c);
      digitalWrite(SS, LOW);
      SPI.transfer(c);
      digitalWrite(SS, HIGH);
    }
  }
  else
    Serial.println("File failed to open");  
} 

void loop() {}

Thank you.
I think your code does my first half of my work...i really appreciate if u give any hint how to send data(which is read from text file) from sd card to arduino using spi.

ashritha:
I think your code does my first half of my work...i really appreciate if u give any hint how to send data(which is read from text file) from sd card to arduino using spi.

That's this part:

      digitalWrite(SS, LOW);
      SPI.transfer(c);
      digitalWrite(SS, HIGH);

ok thanks
how to send this data to another arduino which is a slave

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

File file;
const int chipSelect = 10;  /*for arduino*/
const int ss = 9; /*for sdcard*/ 

void setup() {
  Serial.begin(57600);    //Begin serial communication
  SPI.begin();
  pinMode (10,OUTPUT);
  if (!SD.begin(9)) {     //Check that SD card is initialized
    Serial.println("SD not initialized");
    return;
  }
  else {
    Serial.println("SD initialized");
  }
  file = SD.open("logdata.txt");  //Open file
  if(file) {
    Serial.println("File opened");  
    while (file.available()) {
      char c = file.read();
      Serial.write(c);
      digitalWrite(SS, LOW);
      SPI.transfer(c);
      digitalWrite(SS, HIGH);
    }
  }
  else
    Serial.println("File failed to open");  
} 



void loop() {

digitalWrite(chipselect, HIGH);  // ensure SS stays high

  // Put SCK, MOSI, SS pins into output mode
  // also put SCK, MOSI into LOW state, and SS into HIGH state.
  // Then put SPI hardware into Master mode and turn SPI on
  SPI.begin ();

  delay (5000);  // 5 seconds delay to start logic analyser.

  char c;
  
  // enable Slave Select
  digitalWrite(chipselect, LOW);    // SS is pin 10
  
  // send test string
  for (const char * p = "h/n" ; c = *p; p++)
    SPI.transfer (c);

 // disable Slave Select
 digitalWrite(chipselect, HIGH);

 // turn SPI hardware off
 SPI.end ();
 
 while (1);  //loop

}

is this correct?

is this correct?

If it works, it is. If it doesn't it isn't. It isn't rocket science to tell the difference.