I'm working a sort of "restaurant" implementation in C with client-server. I am trying to send the following structure through a FIFO:
typedef struct {
int numtable; //table number to send answer
char timestamp[20]; //simple timestamp
int order[MENUSZ]; //array of int with dish IDs
} request;
About this struct, I basically send to the server the table number, to "build" the client FIFO name through a template, a timestamp, and order is a simple array filled with randomly chosen integers to "create" a sort of random menu request. With this setup I didn't have problems, using
write(server_fd, &request, sizeof(request))
I had problems when I wanted to transform the array order[MENUSZ] in a pointer, to make a dynamic array, like this:
typedef struct {
int numtable;
char timestamp[20];
int *order;
} request;
After changing the struct, I used the malloc function to allocate enough space for the array:
request->order = malloc(sizeof(int)*numclients+1);
The array is fullfilled correctly, but for some reason the server can't read from the FIFO after I added this pointer, by doing
read(server_fd, &request, sizeof(request));
I can't figure out why it doesn't work with this pointer. Am I doing something wrong?