2014-09-16 17 views
0

Codeblocks에서이 코드를 실행하는 데 문제가 있습니다. 코드를 실행하면 오류가 발생한 후 scanf 행까지 잘 돌아가고 코드가 실행을 멈 춥니 다.프로그램 실행 중 오류가 발생했습니다.

#include <stdio.h> 
#include <ctype.h> 

int main(){ 
    char lower, upper, option; 

     puts("Type '.' to end the program."); 
     printf("U-to upper\nL-to lower\n"); 
     fflush(stdin); 
     scanf("%c", option); 
     switch(option){ 
      case 'u': 
      case 'U': 
       do{ 
        fflush(stdin); 
        lower=getchar(); 
        upper=toupper(lower); 
        putchar(upper); 
       }while(lower!='.'); 
       break; 
      case 'l': 
      case 'L': 
       do{ 
        fflush(stdin); 
        upper=getchar(); 
        lower=tolower(upper); 
        putchar(lower); 
       }while(upper!='.'); 
       break; 
     } 
    return 0; 
} 
+0

'scanf ("% c", 옵션);'has no & – Haris

+0

경고 수준을 올리십시오. –

+0

[Scanf가 C 프로그램을 중단시키는 원인] 중복 가능 (http://stackoverflow.com/questions/8281054/scanf-causes-c-program-to-crash) –

답변

0

변경 라인 scanf("%c", option); 다음과 같이

scanf("%c", &option); 

지금 프로그램이 잘 작동합니다. &이 필요합니다. %입니다.

+0

감사합니다! 잘 작동합니다. –

관련 문제