There are a multitude of ways to do this. First you should read up on how strings are handled in C.
eg:
http://www.cs.cf.ac.uk/Dave/C/node19.html
http://www.exforsys.com/tutorials/c-...ings-in-c.html
once you understand strings then:
Next I recommend that you read up on fscanf() and scanf() before you try to continue.
eg:
http://www.cplusplus.com/reference/c...io/fscanf.html
here are a few different ways to solve your problem that you might want to look at:
(these are by no means complete or the best ways to implement your menu. Use them to better understand using %s and %c)
Code:
#include <stdio.h>
#include <string.h>
int main(int argc, char * argv[])
{
// Mainline Variable Declarations
FILE * output = stdout;
FILE * input = stdin;
char selection[256];
do
{
fprintf(output,"1. First name\n2. ISO setting\n3. Aperture setting\n\nPlease enter a menu number or '?' for help\n");
fscanf(input,"%s",selection);
} while (strcmp(selection,"Q") != 0);
}
Code:
#include <stdio.h>
#include <string.h>
int main(int argc, char * argv[])
{
// Mainline Variable Declarations
FILE * output = stdout;
FILE * input = stdin;
char selection[256];
while (1)
{
fprintf(output,"1. First name\n2. ISO setting\n3. Aperture setting\n\nPlease enter a menu number or '?' for help\n");
fscanf(input,"%s",selection);
if (strcmp(selection,"Q") != 0 || selection[0]=='Q')
{
break;
}
}
}
Code:
#include <stdio.h>
#include <string.h>
int main(int argc, char * argv[])
{
// Mainline Variable Declarations
FILE * output = stdout;
FILE * input = stdin;
char selection[256];
while (1)
{
fprintf(output,"1. First name\n2. ISO setting\n3. Aperture setting\n\nPlease enter a menu number or '?' for help\n");
fscanf(input, "%s", selection);
if ('Q' == selection[0])
{
fprintf(output, "\nYou chose to quit!\n");
break;
}
switch (selection[0])
{
case '1':
/*do menu 1 stuff*/
break;
case '2':
/*do menu 2 stuff*/
break;
case '3':
/*do menu 3 stuff*/
break;
case '?':
/*display help menu!*/
break;
default :
fprintf(output, "\n%c is NOT a valid selection\n", selection[0]);
break;
}
}
}