How can I set data into the array of 3 rows which at the same time has an array of 4 elements?
#include <stdio.h>
#include <stdlib.h>
#include "string.h"
typedef struct
{
char value[6];
} MyType;
typedef struct
{
int size;
MyType *values;
} NewType;
static NewType car;
static MyType mytype = {{'\0'}};
void Init(NewType *car)
{
car->size = 3; // Will contain 3 rows of 4 elements
car->values = (MyType*) calloc(car->size,sizeof(MyType));
}
// Get data into
void Write(NewType *car, MyType *data)
{
strcpy(car->values[0].value, data[0].value); // ** Here is where complains
printf("%d\n", car->values[0]); // Printing wrong data!
}
int main()
{
Init(&car);
strcpy(mytype.value, "Hello");
Write(&car, &mytype);
system("PAUSE");
}
printfto show? If you change it toprintf("%s\n", car->values[0].value);, then it will printHello.