Quit when user enter "STOP"

Discussion in 'C' started by cnoobprogrammer, Mar 30, 2012.

  1. cnoobprogrammer

    cnoobprogrammer New Member

    Joined:
    Mar 29, 2012
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    0
    Hi,

    I am a novice in C Programming. And I have some problem regarding to using while or do while loop to quit when user enter "STOP". I have a case statement which will execute this. And I wanted to quit user input when "done" is entered by the user.

    The following is my code:

    case 2:
    printf("Enter name and their id");
    while (strcmp(name,"stop")!=0)
    {
    scanf("%s %d",name,&id);
    /*create customer record function here so after every scan, i will pass in the parameters name and id*/
    }
    break;



    I will appreciate any help and thank you!:nice:
     
  2. dearvivekkumar

    dearvivekkumar New Member

    Joined:
    Feb 21, 2012
    Messages:
    29
    Likes Received:
    5
    Trophy Points:
    0
    Code:
    char name[100] = {'\0'};
    int id = -1;
    do
    {
        printf("Enter name -> ");
        scanf("%s", &name);
        printf("Enter id - > ");
        scanf("%d", &id);
    }while(strcmp(name, "stop") == 0);
    
    
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice