Reading from file and instantly writting to an HTTP client

Hi,

Does anyone has any idea why this code works:

while (myFile.available()) {  
              client.print(myFile.read());
            }

and this one doesn´t:

while (myFile.available()) {
              a = myFile.read();
              client.print(a);
            }

(variable a, is a char)

Cheers

Sorry i made a mistake:

This is the correct way to put the problem:

Does anyone has any idea why this [u]code doesn´t[/u] work:

while (myFile.available()) {  
              client.print(myFile.read());
            }

and [u]this works[/u]:

while (myFile.available()) {
              a = myFile.read();
              client.print(a);
            }

(variable a, is a char)

Cheers

Perhaps this is a clue:

int File::read() {
  if (_file) 
    return _file->read();
  return -1;
}

// buffered read for more efficient, high speed reading
int File::read(void *buf, uint16_t nbyte) {
  if (_file) 
    return _file->read(buf, nbyte);
  return 0;
}

Since File::read returns an int, you are calling client.print() with an int, which is doing what you asked, but not what you expected.

By storing the value in a character variable, a different overload of client.print() is invoked, and this version does what you expect.

Yap, makes sense!

Thank you