i dont know why the list returned is NULL, this is the code:
In my List.h
struct nodo_ {
char* dato;
struct nodo_ *next;
};
struct nodo_ *Lista;
/*Def list */
void createList(struct nodo_ **Lista);
in my main.c
struct nodo_ *Lista;
int main(){
createList(Lista);
while(Lista != NULL){
printf("The date is %s\n ",Lista->dato); //Error here now
Lisa = Lista->next;
}
return 0 ;
}
in my List.c im create the List :
void createList(struct nodo_ *Lista){
struct nodo_ *Aux_List = list_D;
aux_List = malloc(sizeof(struct nodo_));
char* path_a = "Hello";
char* path_B = "Minasan";
/* Store */
aux_List->dato = path_a;
aux_List = Aux_List->next;
aux_List = malloc(sizeof(struct nodo_));
aux_List->dato = path_b;
aux_List->next = NULL;
}
Thanks.
That pointer is being passed by value, i.e., a copy is made. If you wish to initialize the pointer to a completely new value then you must use another level of indirection (i.e., a
nodo_**).On a side note,
typedefing pointer types is almost always a bad idea unless the type is truly opaque (which yours is not). One reason for this “rule” is evident when you consider another bug in your code:You’re allocating space for a pointer to
noda_, not enough for anoda_object. Also, don’t cast the return value ofmallocin C. It is redundant as avoid*is safely and implicitly converted to any other pointer type and, if you forget to includestdlib.h,mallocwill be assumed to be a function which returnsint, and the cast hides the error. (only applies to compilers which implement C89 or an older version)EDIT:
To initialize a pointer argument within a function: