我从这个网站阅读了代码:http: //www.codeproject.com/Articles/24684/How-to-create-Linked-list-using-CC,但它给了我分段错误,我不太明白.
*我将其修改为我的结构
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;
}
这段代码有什么问题?
好的,这个问题解决了。谢谢Guyz'^'!您是否知道如何将字符 " (ASCII 34) 放入 printf 字符串中?(例如,如果我执行 printf("Print this "sentence""); 它会在句子中给我错误,cut I cast another set of “”里面有一个“”。谢谢一堆。