I read the code from this site: http://www.codeproject.com/Articles/24684/How-to-create-Linked-list-using-C-C, but it gave me segmentation fault and I don't quite get it.
*I modified it to my struct
struct Node
{
int type;
char cmd[256];
struct Node *next;
};
struct Node *head = NULL;
void insert(int val, char arr[])
{
struct Node *temp1 = (struct Node*)malloc(sizeof(struct Node));
struct Node *temp2 = (struct Node*)malloc(sizeof(struct Node));
temp1 = head;
while(temp1->next != NULL)
temp1 = temp1->next;
temp2->type = val;
strcpy(temp2->cmd, arr);
temp2->next = NULL;
temp1->next = temp2;
}
What is wrong with this code?
OK, this problem is solved. Thx Guyz '^'! Do you know by any chance how to put charcters " (ASCII 34) into a printf string? (e.g. if I do printf("Print this "sentence""); it would give me error in sentence, cut I casted another set of "" inside a "". Thx a bunch.