Thread: How to do the option for Yes and No?

  1. #16
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    you are wrong about
    scanf("%s",&customer_name);

    it has problems itself even with the single word names - & should be lost

    the fix for reading till the end of line instead of till the first whitespace is easy:

    scanf("%29[^\n]",customer_name);

    I have added the 29 - width specifier to avoid buffer overrun on very long names

    in this case you will need to skip the rest of the line for next read to succed
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  2. #17
    Registered User
    Join Date
    Mar 2009
    Posts
    16
    Do u mean like this?
    It skips the name ?

    Code:
    printf("\nEnter customer name              :  ");
    scanf("%29[^\n]",customer_name);
    printf("\nEnter weight [KG]                :  ");
    scanf("%f",&weight);

  3. #18
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    try this
    scanf(" %29[^\n]",customer_name);
    to skip \n char left by the previous scanf
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  4. #19
    Registered User
    Join Date
    Mar 2009
    Posts
    16
    Thanks Vart!
    now its all ok!

Popular pages Recent additions subscribe to a feed