Saving array to sd card, coming up with an error

cannot initialize a parameter of type ‘unit8_t ’ (aka 'unsigned char’ with lvalue of type ‘unit8_t [5][3000]’

what does this error mean and how do i fix? i got my code from here: SD Card Help - Programming Support / VEX Coding Studio Tech Support - VEX Forum

and yes i got the fixed one.

Share your code, please. It’s not possible to help you without it.

there you go.

The savefile method cannot be used with 2d arrays. You will need to manually save to the files using loops and such. I recommend using file streams for this.

1 Like

is there anyway to save a 2d array? in any way shape or form?

sure it can, they are just buffers.

    // write test data to SD Card
    int nWritten = Brain.SDcard.savefile( "test.h", (uint8_t *)shadow_auton, sizeof(shadow_auton) );

it comes up error free. thank you so much.

Didn’t realize you could do this, thanks for sharing!

actually wait. now i need help getting the array from the file itself. how do i do that? im sorry, im very new to the world of SD cards.

You wrote around 15k bytes of binary data to the file, what did you want to do with it ?


so basically im writing code that it reads the drivers input every time they move, and then it saves it to a 2d array, then it saves that array to a file. then when you run auton, it loads the 2d array again and redoes all the functions, exactly as the driver did. its possible, as another team in our school did it, but it took them 3 months to make work. however, im actually doing quite well right now. it seems to work very well at the moment because i made an improved system of tracking it, which i believe they did not have. however they refuse to share their code for some reason. they call it a shadow auton. so im replicating their thing, and the last part of the puzzle i need now is it loading the array, and from there my program takes it away.

The dumbed down way (ie. without using more standard C or C++ file access calls) is to just use loadfile, pass it the same buffer pointer and max size and it will just read in that data if it is available.

 * @return Returns the number of bytes read from the file.
 * @brief Loads a file from the SD card.
 * @param name The name of the file.
 * @param buffer Pointer to a buffer for file data.
 * @param len The length of the buffer in bytes. Usually set to the max length of the buffer.
int32_t loadfile(const char *name, uint8_t *buffer, int32_t len );

 * @brief Saves a file to the SD card.
 * @return Returns the number of bytes saved to the file.
 * @param name The name of the file.
 * @param buffer Pointer to a buffer with file data.
 * @param len The length of the buffer in bytes. Usually set to the max length of the buffer.
int32_t savefile(const char *name, uint8_t *buffer, int32_t len );


i dont really understand what a buffer is. im gonna have to research that. thank you for your help, if i need more i know who to ask!

A buffer is just an area of continuous memory. Most of the time it’s just an array.

uint8_t   buffer[1024];

A 1024 byte buffer.

As 2d arrays are also continuous memory you can also use them if you know the dimensions.

uint8_t   another_buffer[2][1024];

will be 2048 bytes long.

(just make sure they are not on the stack, ie. make large buffers global)


int32_t loadfile(const char shadow_auton, uint8_t myReadBuffer, int32_t autonLength);

so thats what i have, how does it know what file to open? cant test the code right now since its 9 o clock at night and im not at school, so

Just follow the same format as savefile. something like

int nRead = Brain.SDcard.loadfile( "test.h", (uint8_t *)shadow_auton, sizeof(shadow_auton) );

to read into the same buffer as you wrote (shadow_auton)

then check that nRead is the same size as the array.


To give a simplified answer, a buffer tells the computer to set aside memory, in bytes, for an object (objects like ints, strings, streams, arrays, etc).

Grab a cup. That “space” inside the cup is like a buffer. If you fill the cup with water, as long as the amount of water is <= the size of the cup you are fine. But as soon as the amount of water is greater than the size of the cup then the water will overflow. As long as the size you declare as the buffer is greater than the size of the objects you put in it you’ll be okay. But as soon as the size of the object exceeds the buffer, then you’ll get an “overflow error.”


shadow_auton is the array. im not sure why i have that as the buffer. so i relace that with my variable myReadBuffer and then i just have to sit back and let C++ do its thing? i see a * in there. i believe thats a pointer. What is this file that it’s saving? Is it saving my array or not?