我想要做的是訪問C中的多維字符串數組中的字符串值。字符串實際上是一個數字值,我希望以整數值存儲。將字符串轉換爲int c
當我嘗試打印的值如下
printf("TESTING COMMAND\n");
printf("%d\n",commands[0][0]);
值打印正常預期值
然而,當我嘗試使用它來初始化例如陣列如下面
char **options[ (x - 1) ];
這提供了以下錯誤
error: size of array ‘options’ has non-integer type
其中我想到因爲命令數組聲明如下
char ***commands;
的事情是,即使我嘗試分配一個整數變量來保存這個值,我得到一個分段錯誤
x = command[0][0];
我也嘗試了像strtol
這樣的功能,導致了相同的結果。但是我不確定我是否已經使用了這個功能。
有什麼建議嗎?
int x;
printf("TESTING COMMAND\n");
printf("%d\n",commands[0][0]);
x = command[0][0];
printf("Creating options of size = %d\n", x);
發佈更多代碼,而不僅僅是很小的碎片 – 2015-04-03 22:51:42
'printf(「%d \ n」,commands [0] [0]);'什麼是命令,它是如何定義/聲明的? – wildplasser 2015-04-03 22:51:56
@wildplasser命令被定義爲char ***命令; – 2015-04-03 23:07:00