Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   Quit when user enter "STOP" (http://www.go4expert.com/forums/quit-user-enter-stop-t28117/)

cnoobprogrammer 30Mar2012 17:32

Quit when user enter "STOP"

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*/

I will appreciate any help and thank you!:nice:

dearvivekkumar 31Mar2012 15:51

Re: Quit when user enter "STOP"

char name[100] = {'\0'};
int id = -1;
    printf("Enter name -> ");
    scanf("%s", &name);
    printf("Enter id - > ");
    scanf("%d", &id);
}while(strcmp(name, "stop") == 0);

All times are GMT +5.5. The time now is 19:16.