2
I’ll send the code and the warnings that GCC is reporting. I must ignore warnings?
The warnings are related as the passage of struct
for the job Inserir();
:
#include <stdio.h>
#include <stdlib.h>
int menu();
int PosValida();
int Inserir();
int Inserir(struct Lista *vet, int pos)
{
}
int PosValida()
{
int pos;
do{
printf("Informe Posição da Estrutura Principal\n");
scanf("%d", &pos);
if(pos<0 || pos>10)
printf("Posição Inválida\n");
}while(pos<0 || pos>10);
return pos;
}
typedef struct
{
int PosAtual;
int UltimaPos;
int *VetAux;
}Lista;
int menu()
{
int op;
printf("Digite as opção desejada\n");
printf("0 - Sair\n");
printf("1 - Inserir\n");
scanf("%i", &op);
return op;
}
int main()
{
int op;
int sair = 0;
int Posvalida;
Lista lista_principal[10];
for(int i=0;i<10;i++)
{
lista_principal[i].VetAux=NULL;
lista_principal[i].UltimaPos=0;
lista_principal[i].PosAtual=0;
}
while (!sair){
op = menu();
switch (op){
case 0:{
sair =1;
break;
}
case 1:{ //inserir
Posvalida=PosValida();
Inserir(lista_principal, Posvalida);
break;
}
default:{
printf("opcao inválida\n");
}
}
}
return 0;
}
Teste.c:10:20: warning: ‘struct Lista’ declared inside parameter list int Inserir(struct Lista *vet, int pos) ^ Teste.c:10:20: warning: its scope is only this definition or declaration, which is probably not what you want Teste.c: In function ‘main’: Teste.c:74:25: warning: passing argument 1 of ‘Inserir’ from incompatible pointer type [-Wincompatible-pointer-types] Inserir(lista_principal, Posvalida); ^ Teste.c:10:5: note: expected ‘struct Lista *’ but argument is of type ‘Lista * {aka struct <anonymous> *}’ int Inserir(struct Lista *vet, int pos)
bigown, thanks. As for the struct, I already imagined that this was it, however, without the struct the function gave error. It only solved when I put the struct on top of the other functions, just like you did. Thank you
– Roberto Kennedy
So you have to fix the right mistake and not introduce new ones ;)
– Maniero