0
#include <stdio.h>
#include <stdlib.h>
typedef struct Ecoponto{
int codigo;
int contentores[3];
char *cidade;
char *rua;
int nporta;
}ecoponto;
int insereEcoponto (const struct Ecoponto ecoponto[],int tam,int pos,int codigo,int porta,char* cidade,char* rua){
for(pos=0;pos<tam;pos++){
if(ecoponto[pos].codigo == codigo){
return 0;
}
}
if(pos<tam){
ecoponto[pos].codigo = codigo;
ecoponto[pos].nporta = porta;
ecoponto[pos].cidade = cidade;
ecoponto[pos].rua= rua;
ecoponto[pos].contentores[0] = 0;
ecoponto[pos].contentores[1] = 0;
ecoponto[pos].contentores[2] = 0;
}else{
printf("Vetor cheio.\n");
return 0;
}
}
Mistakes:
main.c:41:30: error: assignment of member 'codigo' in read-only object
ecoponto[pos].codigo = codigo;
^
main.c:42:30: error: assignment of member 'nporta' in read-only object
ecoponto[pos].nporta = porta;
^
main.c:43:30: error: assignment of member 'cidade' in read-only object
ecoponto[pos].cidade = cidade;
^
main.c:44:26: error: assignment of member 'rua' in read-only object
ecoponto[pos].rua= rua;
^
main.c:45:38: error: assignment of read-only location '(ecoponto + (sizetype)((long unsigned int)pos * 40ul))->contentores[0]'
ecoponto[pos].contentores[0] = 0;
^
main.c:46:38: error: assignment of read-only location '(ecoponto + (sizetype)((long unsigned int)pos * 40ul))->contentores[1]'
ecoponto[pos].contentores[1] = 0;
^
main.c:47:38: error: assignment of read-only location '(ecoponto + (sizetype)((long unsigned int)pos * 40ul))->contentores[2]'
ecoponto[pos].contentores[2] = 0;
^
Why I have these mistakes I don’t understand. I know it has to do with ecoponto[pos].""=""
but I don’t see why.
Alias - is not creating "Ecoponto" as a type in typedef, and then using "Ecoponto" as a variable name?
– jsbueno
@jsbueno too. Edited. Thank you for remembering.
– Maniero