--- In [email protected], "John Matthews" <[EMAIL PROTECTED]> wrote:
>
> --- In [email protected], "Oludayo Oguntoyinbo" <dawofe@> wrote:
> >
> >    printf("Enter the type of bread you want to make: \n");
> >    scanf("%c", &type);
> 
> I would use fgets() to read in a line of input, then use sscanf() on
> the line.

...and you could also use a function to simplify:

#include <stdio.h>

static char get_reply(const char *prompt)
{
    char buf[100], c;

    printf("Enter %s:\n", prompt);
    fgets(buf, sizeof buf, stdin);
    sscanf(buf, "%c", &c);

    return c;
}

int main(void)
{
    char type, size, baking_type;

    type = get_reply("the type of bread you want to make");
    size = get_reply("D if the bread size is double else enter N");
    baking_type = get_reply("M if manual baking else enter A");

    printf("type=%c size=%c baking_type=%c\n", type, size, baking_type);
    :

You could then extend the function to only allow valid responses.

John

Reply via email to