2015-11-15 17 views
0

我想創建一個菜單,我的菜單列出了a-d。我希望if語句在菜單中首先讀取第一個項目,但我的程序不斷崩潰。我怎樣才能解決這個問題?用c創建一個菜單

#include <stdio.h> 
#include <string.h> 

int main() 
{ 

    char option[4]; 



    system("cls"); 

    printf("+++++++++++++++++++++++++++++++++++++>>>ATHLETE DATA MANAGEMENT SYSTEM<<<++++++++++++++++++++++++++++++++++++++\n\n"); 
    printf("\t\t\t\t\ta\. Enter Athlete Data\n"); 
    printf("\t\t\t\t\tb\. Determine Distance to Reach World Record\n"); 
    printf("\t\t\t\t\tc\. Display Athlete Management Report\n"); 
    printf("\t\t\t\t\td\. Exit\n"); 


    printf("Type the corresponding letter (a-d) to access the menu. "); 
    scanf("%d", &option); 

    if(strcmp(option, "a")==0){ 
     printf("Welcome to Athlete Data Page\n"); 
    } 
    else if(strcmp(option,"b")==0){ 
     printf("Determine Distance to Reach World Record\n"); 

    }else if(strcmp(option, "c")==0){ 
     printf("Athlete Management Report"); 

    }else if (strcmp(option, "d")==0){ 
     printf("Exit Menu"); 
      printf("Press Y for yes and N for no"); 
     } 
     else{ 
      printf("Incorrect code entered."); 
     } 
      return 0; 
} 
+0

請描述* how * it崩潰。是否有錯誤訊息?它什麼時候崩潰?剛啓動後?編譯期間?按了一些鍵後? – kaleissin

+0

該錯誤是在啓動後它正在說程序已停止工作。 –

回答