問題の解決に問題があります。私はこのコードを試しながら、セグメンテーションフォールト:11エラーを続行します。私がコードを変更するたびに、エラーがポップアップし、どこに欠陥があるかわからないので、誰かが欠陥を見たら私はすばらしいだろう。セグメンテーションフォールト11:10
事前におねがいします。
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "dbg.h"
typedef struct node{
char *data;
struct node *next;
} node_t;
node_t **push(node_t **head, char *data){
node_t *new_node;
new_node = malloc(sizeof(node_t));
new_node->data = data;
new_node->next = *head;
*head = new_node;
free(new_node);
return head;
}
int main(int argc, char *argv[])
{
node_t **head;
char *data = "hoi";
char *data2 = "hallo";
head = malloc(20 * sizeof(node_t));
head = push(head, data);
head = push(head, data2);
printf("%s\n",(*head)[1].data);
free(head);
return 0;
}
segfaultが原因であることを理解していますか?これは1日に10回尋ねられ、答えはほぼ同じです。 – Carcigenicate
あなたはこれを読むのが好きかもしれません:[小さなプログラムをデバッグする方法](https://ericlippert.com/2014/03/05/how-to-debug-small-programs/) – alk
'head = malloc(20 * sizeof (node_t)); '見た目が正しくない!! –