【发布时间】:2013-10-08 14:05:55
【问题描述】:
#include <stdlib.h>
#include <string.h>
int main(void){
double sum=0;
int ii=0;
char buf[256], token[100]; // I am making this "finite length". You need to know how long the line is that you allow...
printf("Enter the numbers to average on a single line, separated by space, then press <ENTER>\n");
gets(buf, 255, stdin);
token = strtok(buf, " ");
while(token != NULL) {
sum += atof(token);
ii++;
token = strtok("", " "); // get next number
}
printf("AVERAGE: ***** %lf\ *****", sum / (double)ii);
return 0;
}
它给出了这个错误- 第 9 行:标准输入未声明 &当我添加 stdio.h 头文件时,它给了我错误- 第 11 行:需要左值
谁能纠正一下?
【问题讨论】:
-
什么编译器? Linux、Win 还是 Mac? 11 号线在哪里?
-
您不能分配给数组名称
token。数组不是指针。 -
先从为什么不在代码中包含 stdio.h 开始。