#include <stdio.h><br />#include <stdlib.h><br />char* menu[] = {<br />"a - add new record",<br />"d = delete record",<br />"q - quit",<br />NULL,<br />};<br />// int func(int a[]) // a is a pointer to the first element of an array<br />// int func(int* a) // is the same as the above one<br />// so I think the below one is equal to char** choices);<br />// int getchoice(char* greet, char* choices[]);<br />int getchoice(char* greet, char** choices);<br />int main()<br />{<br />int choice = 0;<br />do<br />{<br />choice = getchoice("please select an action", menu);<br />printf("you have chosen: %c/n", choice);<br />} while(choice != 'q');<br />exit(0);<br />}<br />int getchoice(char* greet, char** choices)<br />// int getchoice(char* greet, char* choices[])<br />{<br />int chosen = 0;<br />int selected;<br />char** option;<br />do {<br />printf("choice: %s/n", greet);<br />option = choices;<br />while (*option)<br />{<br />printf("%s/n", *option);<br />option++;<br />}<br />// when prog running, when user types 'a' and Enter key, prog see 'a' and<br /> // LF('/n')(10), not the character CR'/r'(13), unix and linux use a single<br />// LF as the end of a line not like in windows it use both the two characters<br />// but still strange happens, this program runs very well in both linux and<br />// windows OS.<br />do // if I typed 'a' and Enter in shell bash, there will be two characters in<br />{ // buffer, character 'a'(97) and character '/n'(10),<br />selected = getchar();<br />} while (selected == '/n'); // discard the '/n'<br />option = choices;<br />while (*option)<br />{<br />if (selected == *option[0])<br />{<br />chosen = 1;<br />break;<br />}<br />option++;<br />}<br />if (!chosen)<br />{<br />printf("incorrect choice, select again/n");<br />}<br />} while (!chosen);<br />return selected;<br />}