Quit when user enter "STOP"

Newbie Member
30Mar2012,17:32   #1
cnoobprogrammer's Avatar
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!
Go4Expert Member
31Mar2012,15:51   #2
dearvivekkumar's Avatar
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);