scoreGrid是得分**,10分数创建*。我试图初始化Score *中的每一个,从名为rank的二进制文件中读取。 Score是一个带int和char [7]的简单结构。“需要作为分配的左操作数[错误]左值”
Score** scoreGrid;
scoreGrid = (Score**)calloc(1,sizeof(Score*)*10);
if(!scoreGrid){
endOnScore();
}
int res, i, j;
for(i=0;i<10;i++){
((*scoreGrid) + i * sizeof(Score*)) = (Score*)malloc(sizeof(Score)); //[Error] lvalue required as left operand of assignment
if(!(*scoreGrid + i * sizeof(Score*))){
endOnScore();
}
res = fread((*scoreGrid + i * sizeof(Score*)),sizeof(Score),1,rank);
printf("res: %d\n", res);
if(res == 0){
free((*scoreGrid + i * sizeof(Score*)));
break;
}
}
我评论,我遇到了错误..有人知道可以吗?也许有更好的解决方案?谢谢!
你对索引寻址有什么反应? –
作业左侧的值不是您想要的值。 * scoreGrid与scoreGrid [0]相同 - 返回第一个指针。您应该在解除引用前添加。 – pticawr
使用调试器找到它 – Anjaneyulu