我一直工作在一个问题,学校在过去的几个小时,一个问题,我不能调试是让我疯狂......çSCANF For循环关闭的1
我能得到这个功能并使用scanf将数字输入到数组中似乎可行,但printf语句在循环的第一次运行时不起作用。
类似的功能在过去的作业中做了同样的事情。我大概有一次性的地方,但我已经搜查,没有运气,所以我在这里有一个引擎收录链接:
#include <stdio.h>
#include <stdlib.h>
#define MAXARRAYSIZE 10
static float * getGrades (int numGrades);
static float * getWeights();
int main(void) {
float * w;
w = getWeights();
return 0;
}
float * getWeights() {
static float weights[MAXARRAYSIZE];
static float temp;
printf("Please enter up to %d numbers representing an evaluation scheme!(between 0>100)\n", MAXARRAYSIZE);
for (int i = 0; MAXARRAYSIZE > i; i++) {
scanf("%f\n", &temp);
printf("temp is: %f\n", temp);
printf("??????????");
if (100 > temp && temp > 0) {
weights[i] = temp;
printf("WEIGHTS[i] %f \n", weights[i]);
} else if (i < 1) {
exit(-1);
} else {
printf("Invalid input!");
return weights;
}
}
return 0;
}
该行是非法的'static float weights [0];'。您的数组未分配。 –
woah woops谢谢!只是改变它,但仍然是同样的问题,虽然:( – mwcmitchell
它不是一个一个,你正在将数据写入_nowhere_作为'静态浮动权重[0];'不分配任何内存 – ForceBru