-2

So i have a struct with the following elements:

typedef struct loja{
    int numero;
    char nome[MAX];
    float area;
    float faturacao[12];
} Loja[N];

i declared an array vetC[ ] for the struct and my next step was to eliminate a posicion of that array

int EliminarComum(int c,Loja vetC[]){    
    int posicao, i,a;  

    posicao = MostrarComum(c,vetC);  ///only for the user to choose the position he wishes to eliminate.
    if (posicao > c)  
        printf("can't delete.\n");  

    else {  
        for (i = posicao - 1; i < c - 1; i++){  
            vetC[i]->numero = vetC[i+1]->numero;  
            vetC[i]->nome = vetC[i+1]->nome;  
            vetC[i]->area = vetC[i+1]->area;  
            for(a=0;a<12;a++)  
                vetC[i]->faturacao[a] = vetC[i+1]->faturacao[a];  
            c--;  
        }  
    }  
    return c;  
}  

and in the line of vetC[i]->nome = vetC[i+1]->nome; gives me the error

error: assignment to expression with array type

nunoPT123
  • 1
  • 3
  • Possible duplicate of [How to copy a char array in C?](https://stackoverflow.com/questions/16645583/how-to-copy-a-char-array-in-c) – UnholySheep Dec 27 '18 at 23:06

1 Answers1

0

You cannot assign arrays, but you could assign complete struct loja-objects:

vetC[i] = vetC[i+1];

Conver, for example, the following simple program, which illustrates how an assignment of struct-objects works, while an assignment of a char-array fails:

struct testStruct {

    int x;
    char str[10];
};

int main() {

    struct testStruct t1 = { 10, "Hello" };
    struct testStruct t2;

    t2 = t1;  // legal.

    char str1[10] = "Hello";
    char str2[10];

    // str2 = str1;  // illegal; arrays cannot be assigned.

    strcpy(str2,str1);  // legal (as long as str1 is a valid string)
}
Stephan Lechner
  • 34,891
  • 4
  • 35
  • 58