我需要撰寫一些代碼,讓我可以讀取input用戶使用的字串,fgets()但第一個字符是有關程式應該做什么的資訊。
例如,在我正在撰寫的程式中,如果input[0] == 'p'我希望它向結構中添加跟隨它的字符,但我嘗試過的每一種方式都失敗了input [2]。input[4]任何人都知道我可以如何分隔字串的各個部分?
uj5u.com熱心網友回復:
int startIndex = 2;
int lastIndex = 4;
char answer[lastIndex - startIndex];
for (int i = startIndex; i <= lastIndex; i ) {
answer[i-startIndex] = input[i];
}
這會抓取開始和最后一個索引中的每個字符
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/455484.html
