Thanks guys.
Code supplied:
static void getuserinput(char *prompt, char *reply);
static int getans(char *prompt, char *choices);
int main(int argc, char **argv)
{
char namebuf[NAME_MAX];
char typebuf[NAME_MAX];
char defltbuf[NAME_MAX];
char codebuf[NAME_MAX];
char *eols = "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n";
fputs(eols, stdout); // clear terminal window
//char ans = getans("Make a choice.\n", "123");
// Option variable name.
getuserinput("Enter variable name: ", namebuf);
// Option variable type.
getuserinput("Enter variable type: ", typebuf);
// Option default value.
getuserinput("Enter variable default value: ",
defltbuf);
// Option C code.
getuserinput("Begining with an assignment operator,"
" enter C code for this option:\n ",
codebuf);
return 0;
}
void getuserinput(char *prompt, char *reply)
{
char buf[NAME_MAX];
fputs(prompt, stdout);
char *cp = fgets(buf, NAME_MAX, stdin);
cp = strchr(buf, '\n');
if (cp) *cp = '\0'; // don't need eol in the result
strcpy(reply, buf);
} // getuserinput()
int getans(char *prompt, char *choices)
{
/* Prompt the user with prompt then loop showing choices until
* the user enters something contained in choices.
* Alphabetic choices like "Yn" will be case insensitive.
*/
char testchoices[16];
char shortprompt[80];
fputs(prompt, stdout);
char c;
strcpy(testchoices, choices);
size_t i;
// to be case insensitive when choices is alpha.
for (i = 0; i < strlen(testchoices); i++) {
testchoices[i] = toupper(testchoices[i]);
}
sprintf(shortprompt, "Choose one of: \"%s\" ", choices);
while (1) {
fputs(shortprompt, stdout);
fflush(stdin);
scanf(" %c", &c);
c = toupper(c);
if (strchr(testchoices, c)) {
break;
}
}
return c;
} // getans()