// 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, " ");
}
printf("Average is %lf", sum/(double)ii);
}
在線8: char buf [256],* token; 當我改變數組限制爲任何8個或更多的數字數字,如11111111,6829786907(等等),然後程序得到遵守,但在輸出時顯示'Segmention Error'。我如何增加數組限制?我正在使用基於UNIX的系統。請幫我:)如何增加C中數組的限制?
嗯。再次!!我認爲你的編譯器有問題。 – haccks
我沒有得到答案,大聲笑 – user2583127
@haccks你可以嘗試在編譯器上99999999數組大小? – user2583127