0
I need to do a job with this struct
and that contains insertion, search and exclusion by year and printing. Only that I am doubtful in the following code. I need right after insertion to be ordered.
struct mundial{
int ano;
char sede[10];
char campeao[10];
struct mundial *prox;
};
struct mundial *inicio;
void iniciaLista (){
inicio = NULL;
}
bool testaListaVazia (){
return (inicio == NULL);
}
void insereLista(int dado1, char dado2, char dado3){
struct mundial *pt;
pt = new struct mundial;
pt -> ano = dado1;
pt -> sede[10] = dado2;
pt -> campeao[10] = dado3;
pt -> prox = NULL;
if(testaListaVazia()){
inicio = pt;
}else {
pt -> prox = inicio;
inicio = pt;
}
return 1;
}
void viewInsere(){
int t,x;
char sd[10];
char cp[10];
cout<<"\nDigite o ano:";
cin>> t;
cout << "\n Digite a sede:";
cin >> sd[10];
cout << "\nDigite o campeao:";
cin >> cp[10];
x = insereLista(t,sd,cp);
if (x!=1) {
cout<<"Erro na insercao";
}else {
cout<<" inserido com sucesso!";
}
}
What I’m doing wrong?
When I get to headquarters he closes the program
void viewInsere(){
int t,x;
char *sd;
char *cp;
cout<<"\nDigite o ano:";
cin>> t;
cout << "\nDigite a sede:";
cin >> *sd;
cout << "\nDigite o campeao:";
cin >> *cp;
x = insereLista(t, sd, cp);
if (x!=1) {
cout<<"Erro na insercao";
}else {
cout<<" inserido com sucesso!";
}
}
Possible duplicate of Sorted list with struct C++
– silash35
There’s a lot of things wrong with the code, instead of
char dado2, char dado3
should beconst char *dado2, const char *dado3
, and instead of using[10]
, use pointers*
– Sveen
explains me better this instead use [10] to use pointers, I did not understand very well
– Lucas Martins
I’m writing the example
– Sveen