gpt4 book ai didi

c - 功能如何搭配?

转载 作者:行者123 更新时间:2023-11-30 16:41:00 24 4
gpt4 key购买 nike

nrOfMeasurements 应该相当于“用户输入多少个元素”来创建新函数(需要)。当我尝试编译时,出现 intmeasurements_count = getEnter(measurements, LENGTH); 错误,如何修复?

int getEnter(int measurements[COLUMN][LENGTH]){
int x;
for(x=0;x<LENGTH;x++){
printf("Enter number #%d: ", x+1);
scanf("%d", &measurements[COLUMN][x]);

if(measurements[COLUMN][x]==0){
break;
}
}
return x;
}

void nrOfMeasurements(){
int measurements_count = getEnter(measurements, LENGTH);

return;
}

最佳答案

错误是由于第二个函数造成的:

void nrOfMeasurements(){
int measurements_count = getEnter(measurements, LENGTH);

return;
}

引用了变量“measurements”,但是该特定变量未在函数范围内定义。

因此出现错误:

.labo2.c:21:36: error: use of undeclared identifier 'measurements' int measurements_count = getEnter(measurement..

>如何解决?

measurements 必须在函数可用的范围内定义。例如:

void nrOfMeasurements(){
int measurements[COLUMN][LENGTH];
int measurements_count = getEnter(measurements, LENGTH);

return;
}

或者,也许measurements可以是一个全局变量:

int measurements[COLUMN][LENGTH];

void nrOfMeasurements(){
int measurements_count = getEnter(measurements, LENGTH);

return;
}

或者,也许测量可以是函数的参数:

        void nrOfMeasurements(int measurements[COLUMN][LENGTH]){
int measurements_count = getEnter(measurements, LENGTH);

return;
}

关于c - 功能如何搭配?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46432446/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com