0
I’m having trouble creating a main so test if my functions are correct. is a list program on, no need to have menu.
#include <stdio.h>
#include <stdlib.h>
#include <stddef.h>
#include <stdbool.h>
typedef struct {
int info;
struct tipo_lista * prox;
} tipo_lista;
tipo_lista * cria_no (int valor)
{
tipo_lista * novo;
novo = (tipo_lista *)malloc(sizeof(tipo_lista));
novo -> info = valor;
novo -> prox = NULL;
return novo;
}
void inserir_fim (tipo_lista * p, tipo_lista * novo_no)
{
while (p->prox != NULL)
{
p = p->prox;
}
p->prox = novo_no;
}
void inserir_inicio (tipo_lista * p, tipo_lista * novo_no)
{
novo_no -> prox = p;
p = novo_no;
}
bool tem_numero_na_lista (tipo_lista * p, int valor)
{
while (p != NULL)
{
if (p -> info == valor)
{
return true;
}
p = p -> prox;
}
return false;
}
int qtd_nos_lista (tipo_lista * p)
{
int cont = 0;
while (p != NULL)
{
p = p -> prox;
cont++;
}
return cont;
}
tipo_lista * ultimo_no (tipo_lista * p, int valor)
{
while (p -> prox != NULL)
{
p = p -> prox;
}
return p;
}
tipo_lista * encontra_no (tipo_lista * p, int valor)
{
while (p != NULL)
{
if (p -> info == valor)
{
return p;
}
p = p -> prox;
}
return NULL;
}
I couldn’t find your attempt at function in the code
main
. Post it also that we give a analyzed. If in your attempt gave some error, post it too. I have to say that if you managed to make a chained list with dynamic memory allocation, themain
shouldn’t be the problem, so I think your attempt might be closer than expected.– Woss
So I want to test if these functions are correct, I want to call them. I want to know what I call them in the main.
– André
As any function. Enter your list in main and will call the functions normally by passing the list as parameter. To call a function, just do
nome_da_funcao(parametros)
and, if return,variavel = nome_da_funcao(parametros)
.– Woss