2014-01-24 2 views
0

[링커 오류] C : \ Users 등이 계속 발생하며 collect2 : Id가 프로그램에서 종료 상태 코드 오류 1 개를 반환했지만 잘못된 내용은 표시되지 않습니다. <ctype.h> 헤더를 추가하고 컴파일러 경고를 켜문자열의 모음 및 자음 개수를 계산합니다.

toUpper(string[i]) 

toupper(string[i]) 

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

int main(){ 
int vowels = 0, cnsnts = 0; 
int i, length; 
char string[100]; 

printf("Enter sentence:"); 
gets(string); 
length = strlen(string); 

for(i = 0; i < length; i++){ 
    switch(toUpper(string[i])){ 
     case 'A': 
      vowels++; 
      break; 
     case 'E': 
      vowels++; 
      break; 
     case 'I': 
      vowels++; 
      break; 
     case 'O': 
      vowels++; 
      break; 
     case 'U': 
      vowels++; 
      break; 
     default: 
      cnsnts++; 
    } 
} 

printf("The number of vowels are %d.\n", vowels); 
printf("The number of consonants are %d.\n", cnsnts); 

system("pause"); 
return 0; 

} 
+0

스페이스 전에 모든 isalpha와 편지가 있음을 확인하는 것이 좋습니다. – Ghost

+0

@Ghost와 모든 영숫자가 아닙니다. –

답변

5

변경 : 이것은 내 프로그램입니다.

+2

감사합니다. 지금 작동 중입니다. 그건 절름발이 였어. 방해해서 죄송합니다 – confusedcat

1

먼저

#include <ctype.h> 

후 너무

toupper(string[i]) 
0

당신이해야 #include <ctype.h>처럼 낙타의 경우 toUpper을 변경, 추가 및 실수로 upperu를 대문자로했다. 스위치를 약간 내려 놓을 수도 있습니다.

switch(toupper(string[i])) { 
    case 'A': 
    case 'E': 
    case 'I': 
    case 'O': 
    case 'U': 
     vowels++; 
     break; 
    default: 
     cnsnts++; 
} 

이 스타일은 폴스 스루를 이용합니다. 케이스가 break (또는 return, continue 또는 goto)으로 끝나지 않으면 케이스 아래에 입력됩니다. 이것은 제어 흐름 변경 키워드가 부딪 힐 때까지 계속됩니다. 위의 스위치는 원래와 기능적으로 동일하지만 훨씬 짧습니다.

또한 모음이나 자음하지 string[i]switch

if (!isalpha(string[i])) continue; 
관련 문제