how to Read data from sd card and stores in variable?

In my sd card having text file which contains some data like multiple name, location and distance.

how to i read it and stores in different variables?

Text file like;

#name:xxxxx ;
#age:25;
#location:yyyyy;
#distance:1234;
#starting:25-234;


#name:yyyyyy;
#....
....
....
....

so on.

Like this.. here every variable starts with '#'. foe new data '*' is mentioned. Please help for coding.

Thanks in advance.

The variable that your looking for is called a struct; you need to define it yourself. It's composed of variables of standard types.

struct WHATEVER
{
  // 15 character name plus nul terminator
  char name[16];
  byte age;
  // 5 character location plus nul terminator
  char location[6];
  int distance;
  // 9 characters plus nul terminator
  char starting[10];
};

WHATEVER data;

Adjust to your needs

Read a line character by character into a nul terminated character array; lines end with either '\n', '\r' or '\r' followed by '\n'. Assuming you created the file yourself, you should know what the line-ending is. Strip of the line-ending and the semi colon by replacing them by the nul terminator '\0'.

Next split the line on the colon using strchr or strtok
You will now know which field you have and what the data is.

Below demonstrates how to use the struct; it assumes that you can read a line from the file (check examples for the SD library)

struct WHATEVER
{
  // 15 character name plus nul terminator
  char name[16];
  byte age;
  // 5 character location plus nul terminator
  char location[6];
  int distance;
  // 9 characters plus nul terminator
  char starting[10];
};

WHATEVER data;


void setup()
{
  // variable to hold a line; max 24 characters plus nul terminator
  char line[25];

  // dummy populate with data from file
  strcpy(line, "#name:xxxxx");

  char *ptr = strchr(line, ':');
  if(ptr == NULL)
  {
    // error, no colon
  }
  else
  {
    // replace colon by nul terminator
    *ptr = '\0';
    // increment ptr; after that it points to the value
    ptr++;
    // if it's name field
    if(strcmp(line, "#name") == 0)
    {
      // copy data for name to data structure
      strcpy(data.name, ptr);
    }
    // if it's age field
    else if(strcmp(line, "#age") == 0)
    {
      // copy data for name to data structure
      data.age = atoi(ptr);
    }
  }
}

void loop()
{

}

strcmp
strcpy
atoi

This should give you something to play with.

Thanks for your suggestion. Actually that data is in sd card. How do i read the data and how do i find the line is over??

If possible please provide the example.

Thanks.

The IDE comes with SD examples; you can try to understand e.g. the DumpFile example. You can place characters that you read from file in a character array (instead of echoing to serial monitor).

You can use the principle of example 2 in Serial Input Basics - updated; that will read serial data into a nul terminated character array and when a '\n' is encountered it has 'read a line'. Reading from file is basically the same as reading from serial port.

Come up with something and if you're stuck post your code here so people can point out where you go wrong and help you correct it.