Write to SDcard function question

Hi,

I have been trying to write an array of characters to a file in the SDcard using the write function.

The definition of the funtion in the arduino.cc is the following:

write()

Description
Write data to the file.

Syntax
file.write(data)
file.write(buf, len)

Parameters
file: an instance of the File class (returned by SD.open())
data: the byte, char, or string (char *) to write
buf: an array of characters or bytes
len: the number of elements in buf

Shouldn´t i be able to do the following, declarations and use of the write function:

...
File myFile;
char buff[10] = {'1','2','3','4','5','6','7','8','9','0'};
...
...
myFile.write(buff,9);
...

Apparently i can´t get this myFile.write(buff,9); to compile.
Isn´t it possible to write entire buffers to a file?

Regards

And the error message was ??????

Post all your code and all the error messages (its the first few error messages which we need to see.

Mark

Try

byte buff[10] = {'1','2','3','4','5','6','7','8','9','0'};

or

myFile.write((byte*)buff,9);

MarkT

You are correct!

They refer that: buf: an array of characters or bytes

So it should accept a char array, no?
Apparently if you define byte you don´t even need to do the cast.
If you define as char array and do the cast to (byte *) it works to.

But, using char array and no cast it doesn´t work, can you explain? shouldn´t char work, or there is a small error in the documentation?

char is not the same type as byte so no it should not compile.

Mark

I understand that but in the documentation they say that buf is:

buf: an array of characters or bytes

So char should work according to the documentation, no?

So char should work according to the documentation, no?

Yes, but that does NOT necessarily mean without a cast.

Keep in mind that sometimes documentation is written before the code, and sometimes it's written by people that couldn't code there way out of a wet paper bag.

The REAL documentation is in the .h and .cpp files.

PaulS:
The REAL documentation is in the .h and .cpp files.

That's the code, Paul. Documentation should explain how to use it.

Unfortunately the Arduino online API documentation is very poor and doesn't actually provide the information a programmer would need to use the API. This lack is quite surprising, given how many ways there are nowadays to autogenerate this type of documentation from the code. As a result, people coding against the API and needing to know what the actual method signatures are, are left having to look at the code for themselves. Of course, the documentation doesn't even provide any reference to the relevant source code so we're left to find this for ourselves too. It's nice having a free IDE and a free runtime library, but free software comes at a cost. In this case, the cost is quality.

Watch the subtle difference between a character and a char .

To add to PeterH's faster response:
Be happy they use the avrgcc compiler as is, and don't write their own, just to implement it the way they document it.
Documentation is nice, but if in doubt, read the include file.
If still in doubt, reat the source code, it's open.

You are all correct.

My main worry was that i didn´t understood the behaviour of the compiler accordingly to the documentation...
I failed to consult the code, should have done that...