我一直在努力做這個功課一段時間。我似乎無法找到它的問題。分段錯誤錯誤;絕對值表
我的問題是,爲什麼我不斷收到分段錯誤的錯誤,每次我執行這個程序。
/* Description: A program that takes an input array argument with type double values and displays a table of those inputs and their absolute values.
*/
...
int main() /* Main Function */
{
/* Variables */
int size=5,n;
double value[n];
double table;
/* Instructions and Input */
for(n=0;n<size;n++){
printf("\nPlease enter value #%d:\n",n);
if(n=size-1){printf("\nPlease enter the last value.\n");}
scanf("%lf",&value[n]);
}
/* Recalling the Function and Output */
printf("\nValue\t|Value|\n"); /* Table Header */
table=abs_table(value[n],size); /*Absolute Value Table */
return 0;
}
double abs_table(double value, int size) /* Absolute Value Function */
{
int i,j; /* Counter Variables */
double v;
for(j=1;j<=size;j++){ /* For the Number of rows */
for(i=0;i<=size;i++){ /* For the number of columns */
v = abs(value); // For the absolute values */
printf("\n%g\t%g\n",value,v);
}
printf("\n"); /* To make sure the rows display on their own line */
}
return;
}
'雙值[N];''N'將不會被初始化,從而未定義。在任何情況下,都不應該允許編譯編譯器警告('-Wall' for GCC)。 – Kninnug
錯誤,錯誤無處不在。 – Kunal
解決所問的唯一問題,因爲由於局部變量中的值不確定而導致未定義的行爲。 – WhozCraig