我不知道我的代码有什么问题。我在做一个 OS 时间调度程序,我才刚刚开始编写代码,当我尝试检查它是否运行正确时,我遇到了错误。
这是我的功能:
void npefcfs()
{
int process;
int bt[10];
printf(" How many process do you like to use: ");
scanf("%d",&process);
printf("\n -----------------------------------------");
printf("\n Please Enter Burst time: ");
for (int i = 0; i < process; i++)
{
int num = 1;
printf("\nP%d =",num);
num = num + 1;
scanf("%d", &bt[i]);
}
for (int k = 0; k < process; k++)
{
printf("%d", &bt[k]);
}
}
我一直有这样的错误
error C2065: 'k' : undeclared identifier
error C2143: syntax error : missing ';' before '{'
我检查了很多次。我想我正确地声明了 K,并且不应该缺少 ';'
最佳答案
for (int i = 0; i < process; i++)
此语法仅适用于 C99,但根据您的错误代码,您使用的是 Visual Studio,它尚不支持 C99。
你需要在代码块的开头声明变量i
k
,C89风格:
void npefcfs()
{
int process;
int i, k;
//...
然后像这样使用它:
for (i = 0; i < process; i++)
关于c - 错误 c2065 和许多其他错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18685806/