Given the following data struct:
typdef struct lista {
int num1, num2;
struct lista* sig;
} nodoNum ;
and a declared nodoNumnodoNum pointer variable, the following function will take said variable and create nodes, link them and stop when the user inputs "0" as the first number and return NULL ora pointer to the first node to the(or a null pointer that was passedif numbers were provided).
nodoNum * crearLista(nodoNum * registro) {
nodoNum * auxNodo;
int tempNum1;
printf("Introducir numero 1 >\n");
scanf("%d", &tempNum1);
if (tempNum1 != 0) {
auxNodo = (nodoNum *) malloc(sizeof(nodoNum));
auxNodo->num1 = tempNum1;
printf("Introducir numero 2 >\n");
scanf("%d", &auxNodo->num2);
auxNodo->sig = crearLista(auxNodo);
return auxNodo;
}
else {
return NULL;
}
}
I have been asking some questions over at stack overflowStack Overflow to understand more about pointers. I have arrived at this solution after a while. I'm interested in knowing if I'm breaking some best practice or where there could be room for improvement. As far as I know, it works...but but as a begginner...Ibeginner, I can never be sure.!