I’m trying to copy data into a unsigned char buffer within an array of structs inside one global struct, but it’s somehow failing. This is what I have:
#define MAX_FILES 12
#define SIZE 512
typedef struct bufDataType {
unsigned char buf[SIZE];
} bufData;
static struct {
int counter;
struct bufDataType myBufData[8];
} Table[MAX_FILES];
memset(Table, 0, sizeof(Table));
int loadData(int j) {
// This is a test buffer
unsigned char bufTest[SIZE];
Table[j].counter = 0;
for (int i = 0; i < 8; i++) {
loadIntoBuf(i,bufTest);
printf("This works %s\n", bufTest);
memcpy(Table[j].myBufData[i].buf, bufTest, SIZE);
printf("This is blank %s\n", Table[j].myBufData[i].buf);
loadIntoBuf(i,Table[j].myBufData[i].buf);
printf("This is blank as well %s\n", Table[j].myBufData[i].buf);
}
}
Is it because I’ve limited the number of struct elements within Table?
(This is actually a comment rather than an answer, but it wouldn’t fit in a comment.)
There is nothing visibly wrong with your code. I tweaked it a bit so I could run it:
and compiled it with
gcc -std=c99 -Wall -Wextra tmp.c -o tmp. Its output was exactly as it should be:so something is wrong in what you’re not showing us.