简体   繁体   中英

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. 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).

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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