*MyFile.h*
typedef char* dado_t;
typedef struct elemento elemento;
typedef struct lista2 lista2;
*MyFile.c*
struct elemento{
dado_t str;
elemento* ant;
elemento* prox;
};
struct lista2{
elemento* primeiro;
elemento* ultimo;
elemento* corrente;
};
void_insert(lista2* l, dado_t d){
elemento* novo = malloc(sizeof(elemento*));
novo->str = malloc(strlen(d) * sizeof(char));
novo->str = d;
l->corrente = novo;
l->primeiro = novo;
l->ultimo = novo;
novo->prox = NULL;
novo->ant = NULL;
}
dado_t replace(lista2* l, dado_t d){
dado_t retorno = malloc(strlen(corrente->str) * sizeof(dado_t));
retorno = corrente->str;
corrente->str = realloc(corrente->str, strlen(d) * sizeof(char));
l->corrente->str = d;
return retorno;
}
爲什麼我得到此錯誤?由於myel->str
是已分配malloc()
的指針。爲什麼錯誤?我使用的是臨時元素*如果錯誤與realloc()的Realloc無效的指針。已終止(核心轉儲)
觀測數據碰巧被阻止:
你已經在malloc後面設置了'myel-> str' d – Dinesh
@Dinesh是的,但是錯誤發生在編譯器到達那裏之前...... = s – PlayHardGoPro
你是否想分享一點你的代碼,因爲調用序列尚不清楚。也許 - realloc之前 - 只需打印myel-> str和d - 可能會提供一些線索 – Dinesh