我写,我有一个值添加到一个抽象的数据表中的代码,但我不知道为什么我不能,因为它显示“错误C2106:'=':左操作数必须是l值“错误。错误C2106:“=”:左操作数必须是左值用C
int top_add(top_string *table, const char index[257], const char other[257]) {
top_remove(&table, index);
if (table->item_count == table->size) {
printf("/n Table is full.");
return -1;
}
/* error C2106: '=' : left operand must be l-value */
table->item[table->item_count].index = index;
/*error C2106: '=' : left operand must be l-value */
table->item[table->item_count].other = other;
table->item_count++;
return 1;
}
我做了一些在网上搜索,但找不到对我来说相对的解决方案。
我会很感激的任何提示。
UPDATE:
typedef struct {
char index[257];
char other[257];
} pair;
typedef struct {
pair *item;
int item_count;
int size;
} top_string;
int top_init(top_string *table, const int size) {
table->item = malloc((size+1)*sizeof(top_string));
table->size = size;
table->item_count = 0;
if (table->item == NULL) {
return 0; /* failed to allocate memory */
} else {
return 1;
}
}
后top_string –
的定义,请告诉我们什么'表 - >项目[表 - > ITEM_COUNT ] .index'和'table-> item [table-> item_count] .other'实际上是。 – m0skit0
'table-> item [table-> item_count] .index'的声明是怎么样的?如果它也是一个数组,那么它可以被分配,你必须通过一些函数复制数据(比如'memcpy')。同样适用于'table-> item [table-> item_count] .other'。 –