#20055: 請各位大大解答


yp10870913 (Pakada)


請問一下:

int i;
char n[i];
while ( cin >> n)
cout << n << "\n";

這樣為甚麼測試可以,到送出就不行了

(

 顯示

 #3: 20% RE (SIGABRT)

 系統呼叫了 abort 函式!
 *** stack smashing detected ***:  terminated
 Aborted (core dumped)

這啥???
)
#20070: Re:請各位大大解答


reina42689 (職業岩龍騎手)


請問一下:

int i;
char n[i];
while ( cin >> n)
cout << n << "\n";

這樣為甚麼測試可以,到送出就不行了

(

 顯示

 #3: 20% RE (SIGABRT)

 系統呼叫了 abort 函式!
 *** stack smashing detected ***:  terminated
 Aborted (core dumped)

這啥???
)

第2行的 char n[i]; 陣列初始化需要初始值,你目前貼出來的部分沒有給予 i 任何值

 

array bound is not an integer constant before ‘]’ token
 char n[i];
         ^