// 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的系統。請幫助:)如何增加數組的限制?
你可以嘗試的malloc,但我不明白爲什麼1111是行不通的。 –
char buf [4000];在Linux上適用於我。 – BjoernD
您必須增加可用於應用程序的堆棧大小。但是1111和6829以及5736應該都可以工作。 – RedX