c - While,switch, case statement -


i'm using while, switch, case statement menu , when runs keeps saying enter choice, know while(1) creates infinite loop there way avoid this?

while(1) {     printf("\nenter choice \n");       scanf("%d",&i);       switch(i)       {             case 1:             {              printf("enter value add beginning: ");              scanf("%c",&value);              begin(value);              display();              break;              }              case 2:              {              printf("enter value add last: ");              scanf("%c",&value);              end(value);              display();              break;              }              case 3:              {              printf("value enter before\n");              scanf("%c",&loc);               printf("enter value add before\n");              scanf("%c",&value);               before(value,loc);              display();              break;              }              case 4 :              {              display();              break;              }        } } 

any appreciated.

while(1) ok. have have conditions finish loop. :

while(1){ ......... if(i == 0)   break; ............ } 

add space @ beginning of every "%d" , "%c",because scanf leaves newline characters in buffer:

"%d"->" %d"  "%c"->" %c" 

Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -