How to convert byte into ascii to extract specific data!

Hi friends I am using SD card for data logging! I want to read some parameters in a file below is the example of data in my file!

mode:IR
15/5/2016
14:33ýInitializing SD card...initialization done.
6.txt:
mode:IR
15/5/2016
14:33
Vset:1000
voltageFinal:1001
Ifinal:6.46nA
IR=154.959
Time selected=60
voltage:0,793,793,793,1002,1002,1002,1002,1002,1002,1001,1001,1001,1003,1003,1003,1002,1002,1002,1001,1001,1001,1002,1002,1002,1002,1002,1002,1002,1002,1002,1002,1002,1002,1001,1001,1001,1001,1001,1001,1003,1003,1003,1002,1002,1002,1002,1002,1002,1002,1002,1002,1001,1001,1001,1003,1003,1003,1002,1002,1002,1002,1002,1002,1002,1002,1002,1002,1002,1002,1002,1002,1002,1002,1002,1002,1002,1002,1002,1002,1002,1002,1002,1002,1002,1002,1002,1002,1002,1002,1002,1001,1001,1001,1003,1003,1003,1002,1002,1002,1002,1002,1002,1002,1002,1002,1001,1001,1001,1002,1002,1002,1003,1003,1003,1003,1003,1003,1002,1002,1002,1001,1001,
current:10.00,10.00,10.00,10.00,10.00,10.00,10.00,10.00,10.00,10.00,10.00,10.00,10.00,10.00,10.00,10.00,10.00,10.00,10.00,10.00,10.00,10.00,10.00,10.00,10.00,10.00,10.00,10.00,10.00,10.00,10.00,10.00,10.00,10.00,10.00,10.00,10.00,10.00,10.00,10.00,10.00,10.00,10.00,10.00,10.00,10.00,10.00,10.00,10.00,10.00,10.00,10.00,10.00,10.00,10.00,10.00,10.00,10.00,10.00,10.00,10.00,10.00,10.00,10.00,10.00,10.00,10.00,10.00,10.00,10.00,10.00,10.00,10.00,10.00,10.00,10.00,10.00,10.00,10.00,10.00,10.00,10.00,10.00,10.00,10.00,10.00,10.00,10.00,10.00,10.00,10.00,10.00,10.00,10.00,10.00,10.00,10.00,10.00,10.00,10.00,10.00,10.00,10.00,10.00,10.00,10.00,10.00,10.00,10.00,10.00,10.00,10.00,10.00,10.00,10.00,10.00,10.00,10.00,10.00,10.00,10.00,10.00,10.00,10.00,10.00,10.00,10.00,10.00,10.00,10.00,10.00,10.00,10.00,10.00,10.00,10.00,10.00,10.00,10.00,10.00,10.00,10.00,10.00,10.00,10.00,10.00,10.00,10.00,10.00,10.00,
IR0.00
10^0,121.8110^9,121.8110^9,121.8110^9,152.0510^9,152.0510^9,152.0510^9,152.0510^9,152.0510^9,152.0510^9,150.3010^9,150.3010^9,150.3010^9,151.0510^9,151.0510^9,151.0510^9,151.8210^9,151.8210^9,151.8210^9,150.0710^9,150.0710^9,150.0710^9,152.0510^9,152.0510^9,152.0510^9,150.9010^9,150.9010^9,150.9010^9,152.2810^9,152.2810^9,152.2810^9,151.1310^9,151.1310^9,151.1310^9,150.5310^9,150.5310^9,150.5310^9,151.9010^9,151.9010^9,151.9010^9,151.9710^9,151.9710^9,151.9710^9,150.6810^9,150.6810^9,150.6810^9,152.0510^9,152.0510^9,152.0510^9,152.0510^9,152.0510^9,152.0510^9,151.6710^9,151.6710^9,151.6710^9,153.6010^9,153.6010^9,153.6010^9,152.0510^9,152.0510^9,152.0510^9,152.7410^9,152.7410^9,152.7410^9,152.2810^9,152.2810^9,152.2810^9,154.1510^9,154.1510^9,154.1510^9,153.9210^9,153.9210^9,153.9210^9,152.7410^9,152.7410^9,152.7410^9,153.6810^9,153.6810^9,153.6810^9,152.9810^9,152.9810^9,152.9810^9,153.4510^9,153.4510^9,153.4510^9,152.5110^9,152.5110^9,152.5110^9,153.2110^9,153.2110^9,153.2110^9,151.6710^9,151.6710^9,151.6710^9,153.6010^9,153.6010^9,153.6010^9,153.6810^9,153.6810^9,153.6810^9,153.4510^9,153.4510^9,153.4510^9,152.2810^9,152.2810^9,152.2810^9,153.5310^9,153.5310^9,153.5310^9,154.3910^9,154.3910^9,154.3910^9,152.9010^9,152.9010^9,152.9010^9,154.5510^9,154.5510^9,154.5510^9,154.3910^9,154.3910^9,154.3910^9,154.9510^9,154.9510^9,

Now I can serially print this by using Serial.write But as U can see if I want to read mode and i want to take that IR out how can I do that? as if I try to compare by putting this all in char array I get ascii values but how to get it in ascii like serial.write?
Basically I just want to read those different values like What is Vset value and V and what was date and those set of IR values how can I do that?
Please guide me any help will be appreciated

Now I can serially print this by using Serial.write

Serial.print() is for converting values to strings, and sending to the serial port. Serial.write() is for sending values, with no conversion, to the serial port. So, your statement does not make sense.

But as U can see if I want to read mode

No, I can't see that.

as if I try to compare by putting this all in char array I get ascii values but how to get it in ascii like serial.write?

How are you getting the data from the file? How are you putting it in an array? Why use a char array is chars is not what you want?

Sorry, I think I was unable to post my question properly!
Let me explain in brief with example!
The file that I read from SD card is 6.txt. when I read this using SD library of inbuild arduino IDE, with following example

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

File myFile;
int h=0;
void setup() {
  // Open serial communications and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }


  Serial.print("Initializing SD card...");

  if (!SD.begin(53)) {
    Serial.println("initialization failed!");
    return;
  }
  Serial.println("initialization done.");

  myFile = SD.open("6.txt");
  if (myFile) {
    Serial.println("6.txt:");

    // read from the file until there's nothing else in it:
    while (myFile.available()) {
      char array[8]={0};
     
      for(int i=0;i<8;i++){
        
        array[i]=myFile.read();
      Serial.write(array[i]);
      Serial.print("     ");
      Serial.println(array[i]);
      }
    }
    // close the file:
    myFile.close();
  } else {
    // if the file didn't open, print an error:
    Serial.println("error opening test.txt");
  }
}

void loop() {
  // nothing happens after setup
}

I get response in following fassion

6.txt:
m m
o o
d d
e e
: :
I I
R R

1 1
5 5
/ /
5 5
/ /
2 2
0 0
1 1
6 6

1 1
4 4
: :
3 3
3 3

V V
s s
e e
t t
: :
1 1
0 0
0 0
0 0

v v
o o
l l
t t
a a
g g
e e
F F
i i
n n
a a
l l
: :
1 1
0 0
0 0
1 1

I I
f f
i i
n n
a a
l l
: :
6 6
. .
4 4
6 6
n n
A A

I I
R R
= =
1 1
5 5
4 4
. .
9 9
5 5

9 9

T T
i i
m m
e e

s s
e e
l l
e e
c c
t t
e e
d d
= =
6 6
0 0

( response is taken from serial print and only small part of that window just to explain the question!)
Now my question is I want to check what is after mode: i.e. whether it is IR or SV or DM ( in this case IR) similarly after voltage final, current final, ir and time selected, now my question is all these strings are different in size so how can I compare those words do I have to compare it sequentially like first check 'm' then again take next character to check 'o' then 'd' then 'e', or is there any way that I can check "mode:"?

I also tried this code but didn't get the output that I expected!

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

File myFile;
int h=0;
void setup() {
  // Open serial communications and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }


  Serial.print("Initializing SD card...");

  if (!SD.begin(53)) {
    Serial.println("initialization failed!");
    return;
  }
  Serial.println("initialization done.");

  myFile = SD.open("6.txt");
  if (myFile) {
    Serial.println("6.txt:");

    // read from the file until there's nothing else in it:
    while (myFile.available()) {
      char array[8];
     String trial; 
      for(int i=0;i<8;i++){
        
        array[i]=myFile.read();
    if(strcmp(array,"mode:")==0){
    Serial.println("I got it");
    delay(500);}
      Serial.println(array);
      }
    }
    // close the file:
    myFile.close();
  } else {
    // if the file didn't open, print an error:
    Serial.println("error opening test.txt");
  }
}

void loop() {
  // nothing happens after setup
}

where on Serial I am expecting message as "I got it" after mode: print but I get this!

6.txt:
m
mo
mod
modeè
mode:
mode:I
mode:IR
mode:IR

ode:IR

1de:IR

15e:IR

15/:IR

15/5IR

15/5/R

15/5/2

15/5/20
115/5/20
165/5/20
16
/5/20
16
5/20
.......

Can any one who could guide me where I am doing wrong!

I think you need to consider how the data is stored in the file. For example it looks as if the first few items are separated by a line feed (I'm just guessing that from the layout of the first 12 lines of output in your Original Post.

Assuming that is correct you should not try to read the whole file but, rather, read the data until you get to a linefeed character.

Have a look at how incoming data is handled in Serial Input Basics. You should be able to apply the same technique to your problem.

If you have a line of data you can use the c string functions to find stuff.

...R

    while (myFile.available()) {
      char array[8]={0};
     
      for(int i=0;i<8;i++){
       
        array[i]=myFile.read();

While there is at least one character left in the file, read all 8 of them. Why?

   if(strcmp(array,"mode:")==0){
    Serial.println("I got it");
    delay(500);}

strcmp() expects a string. array is NOT a string. Learn what distinguishes a string from a char array. Hint: It involves a NULL terminator.

Put the damned } on a new line where it belongs. Put the { on a new line, too. Use Tools + Auto Format, and at least pretend you know what you are doing.

First of all sorry for not putting brackets on new line!
After putting null i got my comparison true so thanks for that guideline!
Robin2 thanks for those links they will help me a lot in the upcoming code!

@robin2 yes that text data in my OP is my actual file!
Now again I got a problem, I was able to find "mode:" by the comparison but when I try to get "voltage" word in it I failed can any one could point out my mistake?
Here is my new code

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

File myFile;
int h = 0;
void setup()
{
  // Open serial communications and wait for port to open:
  Serial.begin(9600);
  while (!Serial)
  {
    ; // wait for serial port to connect. Needed for native USB port only
  }


  Serial.print("Initializing SD card...");

  if (!SD.begin(53))
  {
    Serial.println("initialization failed!");
    return;
  }
  Serial.println("initialization done.");

  myFile = SD.open("6.txt");
  if (myFile)
  {
    Serial.println("6.txt:");

    // read from the file until there's nothing else in it:
    while (myFile.available())
    {
      char array[12];
      String trial;
      for (int i = 0; i < 12; i++)
      {

        array[i] = myFile.read();
        array[i + 1] = '\0';

        if (strcmp(array, "mode:") == 0)
        {
          Serial.println("I got it");
          delay(500);
        }
        if (strcmp(array, "voltage") == 0)
        {
          Serial.println("I got it");
          delay(500);
        }
        Serial.println(array);
      }
    }
    // close the file:
    myFile.close();
  }
  else
  {
    // if the file didn't open, print an error:
    Serial.println("error opening test.txt");
  }
}

void loop() {
  // nothing happens after setup
}

And here is my Serial monitor

6.txt:
m
mo
mod
mode
I got it
mode:
mode:I
mode:IR
mode:IR

mode:IR

mode:IR
1
mode:IR
15
mode:IR
15/
5
5/
5/2
5/20
5/201
5/2016
5/2016

5/2016

5/2016
1
5/2016
14
5/2016
14:
5/2016
14:3
3
3

3

3
V
3
Vs
3
Vse
3
Vset
3
Vset:
3
Vset:1
3
Vset:10
3
Vset:100
3
Vset:1000

v

vo

vol

volt

volta

voltag

voltage

voltageF

voltageFi

voltageFin

So can anyone could guide me about this?

And here is my Serial monitor

Using Serial.println(), I would expect to see:

voltag
voltage
voltageF
voltageFi

Unless array[0] actually contains a line feed.

Now, perhaps, you can see why anonymous printing sucks.

   Serial.print("array contains: [");
   Serial.print(array);
   Serial.println("]");

will show what the problem is, I'm sure.

Thanks got my solution, Here is some modification!

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

File myFile;
int h = 0;
void setup()
{
  // Open serial communications and wait for port to open:
  Serial.begin(9600);
  while (!Serial)
  {
    ; // wait for serial port to connect. Needed for native USB port only
  }


  Serial.print("Initializing SD card...");

  if (!SD.begin(53))
  {
    Serial.println("initialization failed!");
    return;
  }
  Serial.println("initialization done.");

  myFile = SD.open("6.txt");
  if (myFile)
  {
    Serial.println("6.txt:");

    // read from the file until there's nothing else in it:
    while (myFile.available())
    {
      char array[12];
      String trial;
up1:    for (int i = 0; i < 11; i++)
      {

        array[i] = myFile.read();
        if (array[i] == '\0' || array[i] == '\n')
        {
          Serial.println("got new line");
          goto up1;
        }
        array[i + 1] = '\0';

        if (strcmp(array, "mode:") == 0)
        {
          Serial.println("I got it");
          delay(500);
        }

        if (strcmp(array, "voltage") == 0)
        {
          Serial.println("I got it");
          delay(500);
        }
        Serial.print("array contains: [");
        Serial.print(array);
        Serial.println("]");
      }
    }
    // close the file:
    myFile.close();
  }
  else
  {
    // if the file didn't open, print an error:
    Serial.println("error opening test.txt");
  }
}

void loop() {
  // nothing happens after setup
}

and serial monitor is

6.txt:
array contains: [m]
array contains: [mo]
array contains: [mod]
array contains: [mode]
I got it
array contains: [mode:]
array contains: [mode:I]
array contains: [mode:IR]
array contains: [mode:IR
]
got new line
array contains: [1]
array contains: [15]
array contains: [15/]
array contains: [15/5]
array contains: [15/5/]
array contains: [15/5/2]
array contains: [15/5/20]
array contains: [15/5/201]
array contains: [15/5/2016]
array contains: [15/5/2016
]
got new line
array contains: [1]
array contains: [14]
array contains: [14:]
array contains: [14:3]
array contains: [14:33]
array contains: [14:33
]
got new line
array contains: [V]
array contains: [Vs]
array contains: [Vse]
array contains: [Vset]
array contains: [Vset:]
array contains: [Vset:1]
array contains: [Vset:10]
array contains: [Vset:100]
array contains: [Vset:1000]
array contains: [Vset:1000
]
got new line
array contains: [v]
array contains: [vo]
array contains: [vol]
array contains: [volt]
array contains: [volta]
array contains: [voltag]
I got it
array contains: [voltage]
array contains: [voltageF]
array contains: [voltageFi]
array contains: [voltageFin]
array contains: [voltageFina]

You were doing so good, too. Then, you stuck those stupid goto's in there...