你好,我想讀的輸入和增加每個字符的字符串的左側,例如:寫入字符串到左用C
我所做的輸入1,輸出應該是:
1
然後我想添加的號碼2:輸出應該是:
21
然後我想添加的號碼3:輸出應該是:
321
然後我要添加的數量4:輸出應爲:
4321
等...
到目前爲止我已成功的情況下串長度= 0和1:
if(stringLength == 1){
string[ stringLength++ ] = string[ 0 ];
string[ pStringLength - 1 ] = input;
}
else if(stringLength == 0)
string[ stringLength++] = input;
我的問題是在stringLength> 2:
if(stringLength >= 2){
for(indexx = 1; indexx < stringLength; indexx++){
string[ stringLength++ ] = string[ stringLength - indexx ];
}
string[ 0 ] = input;
}
上面的代碼給我分段錯誤,在此先感謝您的幫助! 編輯!!:
if(stringLength >= 2){
for(indexx = 1; indexx < stringLength; indexx++){
string[ stringLength ] = string[ stringLength - indexx ];
}
stringLength++;
string[ 0 ] = input;
}
現在輸出始終限制在2:
如果我有:
21
,我嘗試添加 '3':
32
'1'被刪除,剛剛離開最後2個輸入...
string [stringLength ++]正在使循環無限 – aa1992