I'm doing a college job in C and I've pretty much finished the same. However, I've threaded a bug that I can not seem to get out of. My program, while passing the line aux1=aux1->next;
simply stops working. It stops responding as it does when you give scanf
without using &
before the variable. Does anyone know me answer the why? I think it's basic detail.
Follow the code below:
int addin (lista *no1, lista *no2, lista *no3) {
long int soma;
soma=0;
nodeptr *aux1;
nodeptr *aux2;
aux1=no1->inicio->next;
aux2=no2->inicio->next;
while (aux1 != NULL || aux2 != NULL) {
soma=soma+(aux1->info+aux2->info);
printf ("Voltei aqui");
printf ("\nValor do aux1->info: %d\n", aux1->info);
printf ("\nValor do aux2->info: %d\n", aux2->info);
printf ("\nValor da soma: %d\n", soma);
insereElemento(no3, (soma%100000));
if (soma/100000!=0) {
soma=soma/100000;
}
aux1=aux1->next;
printf ("Valor novo do aux1: %d", aux1->info);
aux2=aux2->next;
printf ("Valor novo do aux2: %d", aux2->info);
}
The declaration of the nodes in the list are given as follows:
typedef struct node {
long int info;
struct node *next;
} nodeptr;
typedef struct {
nodeptr *inicio;
nodeptr *fim;
} lista;
EDIT: Element insertion function in list
int insereElemento (lista *no, int elemento) {
nodeptr *novo = (nodeptr *) malloc (sizeof(nodeptr));
novo->info=elemento;
if (no->inicio==NULL) {
inicializaLista(no);
} else {
no->fim->next=novo;
no->fim=novo;
novo->next=NULL;
printf ("\nElemento inserido com sucesso na lista: %d\n", no->fim->info);
}
}