// C Program to find average of numbers given by user
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void main()
{
double sum = 0;
int ii = 0,c;
char buf[256], *token;
printf("Enter the numbers to average on a single line, separated by space and press enter when done\n");
fgets(buf, 255, stdin);
token = strtok(buf, " ");
while (token != NULL)
{
sum += atof(token);
ii++;
token = strtok(NULL, " "); //Get next number
}
printf("Average is %lf", sum / (double)ii);
}
第 8 行:
char buf[256], *token;
当我将数组限制更改为任何 8 位或更多位数时,例如 11111111、68297907(等等...),程序就会被编译,但在输出时会显示Segmention Error
。
如何增加数组限制?我正在使用基于 UNIX 的系统。