[英]Intelligent Editor program in C
編寫一個智能編輯器來模擬以下內容:
在鍵入時,如果一個新單詞的開頭字母與之前輸入的單詞的字母相同,則應選擇選擇單詞而不是鍵入整個單詞。 這是我的功課。
我的算法:
1: Read the input by everytime checking the _kbhit() macro.
2: Store the word in an array
3: On every further read, check the array if the word exists.
現在出現問題!!!
如何為用戶提供選擇單詞的選項? 即使提供選項成功,我怎么知道用戶已決定選擇該字?
我是這種編程風格的新手。 誰知道怎么做,請幫幫我...
各種各樣的東西使用自動完成....甚至谷歌搜索! 您只需要選擇一個方法,例如,選項卡循環選項,空格選擇該選項(或輸入)。 也許Esc阻止它試圖自動完成該選項。 無論哪種方式,由你來制定計划。 也許嘗試一些其他程序自動完成。
這取決於您如何閱讀輸入,並與用戶進行通信。 如果它只是一個終端,我建議你定義一個鍵(可能是tab或esc)來移動到choosing state
,然后讓他(例如)點擊一個數字(或鍵)。
編輯:一些代碼:
char c=getchar();
//some of your proccessing...
if (c=='\t') {
printf("\nPlease select option (0 to abort)\n");
char **op;
int n,i;
//calculate the options, assign them to op and n.
for (i=0;i<n;i++) printf("%d: %s\n",i+1;op[i]);
i=n+1;
while (i<0 || i>n) scanf("%d",&i);
if (i>0) {
//do whatever you need. remember to use i-1
}
}
//reprint the whole string.
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.