sd card read and compare data

Hello friends...
i want to read a text file from SD card and then i want to compare the data written in text file with the variable in my arduino code, for-example : i have a text file in SD card and in which the data is 1 2 3 4 5 6 7 8 9 10, i want to input a value from serial monitor e.g 1, it then compare the input of serial monitor with the text file data and print out "data matched" if there is 1 available in text file data.
i am using Ethernet shield.

If you are asking permission, it is granted.

If you are asking for help, post your code.

If you are looking for someone to write the code, head over to Gigs and Collaboration and offer to pay.

PaulS:
post your code.

#include <SD.h>

File myFile;
int x,y;
void setup()
{Serial.begin(9600);
   while (!Serial) {
}

Serial.print("Initializing SD card...");
pinMode(10, OUTPUT);
   
  if (!SD.begin(4)) {
    Serial.println("initialization failed!");
    return;
  }
  Serial.println("initialization done.");
myFile = SD.open("test.txt");
  if (myFile) {
    // read from the file until there's nothing else in it:
    while (myFile.available()) {
    	Serial.write(myFile.read());
x = myFile.read();
if (x>10)
{
Serial.println(x);
}
else if ( x >= 48 && x <= 57 ) 
{
y = x - 48;
Serial.println(y);
}
    }
  }
}
void loop() {
}

this code read only one value i think, how can we compare with all of the values?

    while (myFile.available()) {
    	Serial.write(myFile.read());
x = myFile.read();

Open the file. Read one byte and print it. Read another byte and use it in an if test.

Why?

else if ( x >= 48 && x <= 57 )

Hmmm.

else if ( x >= '0' && x <= '9' )

looks a lot more readable, to me.

Of course, the else if will never fire, since the range of values is greater than 10, and the greater than 10 case has already been handled.

Abubakar022:
this code read only one value i think, how can we compare with all of the values?

This code reads each byte in the file and writes it to the serial port.

    // read from the file until there's nothing else in it:
    while (myFile.available()) {
    	Serial.write(myFile.read());

The following statement then tries to read the next byte after the end-of-file, which is unlikely to do anything useful:

x = myFile.read();

If you want to read (part of) the file and compare with data received from the serial port then you can either read each byte from the serial port as it becomes available and then read the corresponding byte from the file to see whether it matches, or you can read the serial input into a buffer and then after the whole string has been received read the corresponding bytes from the file and compare them against the buffer one by one. The first option would use less memory but does not give you a copy of the string that you received - I have no idea whether that would be important to you.

This code reads each byte in the file and writes it to the serial port.

Oops. I missed that. The curly brace jammed up against the statement does not belong there.

PeterH:
If you want to read (part of) the file and compare with data received from the serial port then you can either read each byte from the serial port as it becomes available and then read the corresponding byte from the file to see whether it matches.

can you please give me an example, i don't understand what you are saying.