简体   繁体   English

C中的智能编辑器程序

[英]Intelligent Editor program in C

Write an intelligent editor to simulate the following: 编写一个智能编辑器来模拟以下内容:

While typing if a new word starts with the same letters as that of some previously typed word, the choice of selecting the word instead of typing the whole should be given. 在键入时,如果一个新单词的开头字母与之前输入的单词的字母相同,则应选择选择单词而不是键入整个单词。 This is my homework. 这是我的功课。

My Algorithm : 我的算法:

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.

Now the problem occurs!!! 现在出现问题!!!

How do I give the user an option to select the word or not??? 如何为用户提供选择单词的选项? And even if giving option is successful, how do I know wether user has decided to opt for that word? 即使提供选项成功,我怎么知道用户已决定选择该字?

I am new to this style of programming. 我是这种编程风格的新手。 Anyone knows how to do this, Please help me out... 谁知道怎么做,请帮帮我...

Various things use auto complete.... even google searching! 各种各样的东西使用自动完成....甚至谷歌搜索! You just need to pick a method, eg, tab cycles through options, space selects that option ( or enter ). 您只需要选择一个方法,例如,选项卡循环选项,空格选择该选项(或输入)。 With perhaps Esc to stop it trying to autocomplete that option. 也许Esc阻止它试图自动完成该选项。 Either way, up to you to come up with a scheme. 无论哪种方式,由你来制定计划。 Perhaps try out some other programs autocomplete. 也许尝试一些其他程序自动完成。

It depend on how do you read the input, and communicate with the user. 这取决于您如何阅读输入,并与用户进行通信。 If it's just a terminal, I suggest you to define one key (probably tab or esc) to move to choosing state , and then let him (for example) hit a number (or keys). 如果它只是一个终端,我建议你定义一个键(可能是tab或esc)来移动到choosing state ,然后让他(例如)点击一个数字(或键)。

Edit: some code: 编辑:一些代码:

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM