fscanf(ifile, "%c", &jnk);
/* If there's a height, this will be a ". if not, it'll be a ,*/
if ((jnk = '\"') || (jnk != ',')) {
printf("%c", jnk);
while(fscanf(ifile, "%c", &data) && data != ',' && data != '\"' && data != '\'') {
printf(" %c ", data);
weight[a]= data;
a++;
}
weight[a] = '\0';
player[n].weight=atof(weight);
printf("%.0f ", player[n].weight);
} else if(data == ' ' || data == ',') {
player[n].weight= 0;
printf("%.0f ", player[n].weight);
}
GDB 告诉我将数据存储到权重中会导致段错误。谁能告诉我为什么?
最佳答案
问题出在这里:
我希望您将 "
和 ,
分配给 a。当您使用 weight[a]
时,您会收到错误,因为 ASCII获取字符的值,该值可能超出您声明的数组大小的范围
关于arrays - C 中权重 [a]= 数据上的段错误;,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16509732/