-2

所以我有一个包含以下元素的结构:

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

我为该结构声明了一个数组 vetC[],下一步是消除该数组的一个位置

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;  
}  

并在行中vetC[i]->nome = vetC[i+1]->nome;给了我错误

错误:赋值给数组类型的表达式

4

1 回答 1

0

您不能分配数组,但可以分配完整struct loja的对象:

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

例如,转换下面的简单程序,它说明了 struct-objects 的赋值是如何工作的,而 char-array 的赋值失败:

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)
}
于 2018-12-27T23:09:19.860 回答