如標題所示,我想使用C
-樣式而不是使用庫string
來插入字符在char array
之後,並且請避免使用緩衝區函數,只有基本的:)。在字符數組中的特定位置插入一個字符
char sentence[100],*p = NULL;
cin.get(sentence,100);
char replaceChar; // after What character should we insert
cin>>replaceChar;
char insertingChar; // the character we are inserting after the replaceChar;
cin >> insertingChar ;
p = strchr(sentence , replace);
while(p != NULL){
//and this is I could think of ...
}
所以突然想到說,我們有這樣一句話: 「我要蘋果」,在replaceChar = A,和insertingChar = '*';
結果應該是:「我wa * nt a * pples」。
使用'std :: string'使您的生活更輕鬆。 –
在您的示例中,只有1個'a's'受到影響,是否是由設計決定的? –
nope我有一個問題,當發佈這個,是一個*之後的第一個'a' – JohnnyOnPc