I'm writing some code to interact with dynamic memory that i' creating and i want to know why it's not working.
struct order{
char *bookTitle;
double price;
char *category;
double remain;
int custID;
char processed;
};
typedef struct order order;
struct orderNode{
order *order;
struct orderNode *next;
};
typedef struct orderNode orderNode;
Here is the code creatinng an array or orderNodes and trying to access them. The print statement is giving me a segmentation fault. Not sure why.
orderNode **processQueue = malloc(sizeof(orderNode)*numcats) ;
//sort the orders into their respective categories
//sortOrders(processQueue, unSortedQueue, numcats);
processQueue[1]->order->category = "herro" ;
puts("string set. \n");
printf("%s\n",processQueue[1]->order->category);
/*
gdb backtrace output.
#0 strlen () at ../sysdeps/x86_64/strlen.S:106
#1 0x00007ffff786794c in _IO_puts (str=0x1000000000a2074 <error: Cannot access memory at address 0x1000000000a2074>)
at ioputs.c:36
#2 0x000000000040192f in main (argc=4, argv=0x7fffffffdbd8) at main.c:444
*/
Thanks in advance!