Simple C Program of While Loop and Switch Case

  1. #include < stdio.h >  
  2.   
  3. /* run this program using the console pauser or add your own getch, system("pause") or input loop */  
  4.   
  5. int main(int argc, char * argv[]) {  
  6.     char chc, ok;  
  7.     ok = 'n';  
  8.     while (ok == 'n') {  
  9.         puts("Menu");  
  10.         puts("1. Create a directory");  
  11.         puts("2. Delete a Directory");  
  12.         puts("3. Show a Directory");  
  13.         puts("4. Exit");  
  14.         puts("");  
  15.         switch (chc) {  
  16.             case '1':  
  17.                 puts("Choice is 1");  
  18.                 break;  
  19.             case '2':  
  20.                 puts("Choice is 2");  
  21.                 break;  
  22.             case '3':  
  23.                 puts("Choice is 3");  
  24.                 break;  
  25.             case '4':  
  26.                 puts("Choice is 4");  
  27.                 break;  
  28.             default:  
  29.                 puts("Invalid Choice");  
  30.                 ok = 'n';  
  31.                 return 0;  
  32.                 getch();  
  33.         }  
  34.     }  
  35. }