2014-10-21 4 views
0

이유가 무엇인지 묻고 싶습니다. 런타임 오류 검사 # 2 프로그램을 수행 할 때? 저는 C 프로그래밍을 처음 접했습니다.런타임 검사 오류 # 2 수신

나는 Y/N 키를 입력 한 후 몇 가지 옵션이있는 콘솔 응용 프로그램을 만들려고합니다. 하지만 모든 옵션이 끝나면 오류가 발생합니다.

아무도 내가 그것을 해결할 수있는 방법을 말해 줄 수 없었다 & 프로그래밍의 이런 종류의 일을하는 적절한 방법은 무엇입니까? optionchar 같이

#define _CRT_SECURE_NO_WARNINGS // To allow Visual studio to use "scanf" function 
#include <stdio.h> // Standard Input output . header 
#include <Windows.h> 

void codername() { 
    printf("Coder: Rong Yuan\n"); 
} 

void projectname() { 
    printf("Project name: NPoly Learning\n"); 
} 

void loadcurrentdate() { 
    SYSTEMTIME str_t; 
    GetSystemTime(&str_t); 

    printf("Date: %d . %d . %d \n" 
     , str_t.wDay, str_t.wMonth, str_t.wYear); 
} 

int main() { 
    char option; 
    int input; 
    int mincome, fmember, total; 

    printf("Do you like to see our option? Y/N \n"); 
    scanf("%s", &option); 
    if (option == 'y' || option == 'Y') { 
     printf("1. Display Coder Detail\n"); 
     printf("2. Display Project Name\n"); 
     printf("3. Load Current Date\n"); 
     printf("4. Calculator PCI\n"); 
     printf("5. Exit\n"); 
     scanf("%d", &input); 
    } 
    else 
     exit(1); 

    switch (input) { 
     case 1: 
      codername(); 
      printf("Do you like to return to main?"); 
      break; 

     case 2: 
      projectname(); 
      break; 

     case 3: 
      loadcurrentdate(); 
      break; 

     case 4: 
      printf("Enter your house monthly income: "); 
      scanf("%d", &mincome); 
      printf("Enter total family member: (INCLUDING YOURSELF) "); 
      scanf("%d", &fmember); 
      total = mincome/fmember; 
      printf("Total PCI: %d/%d = %d \n", mincome, fmember, total); 
      system("pause"); 
      break; 

     case 5: 
      exit(0); 
    } 
} 
+2

오류 메시지를 게시물에 복사하십시오. ^^ – SlySherZ

답변

3
scanf("%s", &option); 

은 잘못된 것입니다. 따라서 %s%c으로 바꾸십시오. %s은 문자열 (문자 배열)에 사용해야하고 %c은 문자에 사용되는 형식 지정자입니다.

관련 문제