알파벳 대소문자 변환

2022. 12. 30. 16:59c

728x90
#include <ctype.h>

요 헤더파일에 있는 toupper, tolower 함수 사용해야함

 

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

int main(){
char str[1000];
scanf("%s", str); // zZa 입력받았다고 가정
for(int i=0; i<strlen(str);i++){
    str[i]=toupper(str[i]); //다 대문자로 변환 -->ZZA
    str[i]=tolower(str[i]); //다 소문자로 변환 -->zza
	}
}

대문자인지 소문자인지 확인하는 함수도 저 헤더파일에 있음

if(isupper(str[i])) ...
else if(islower(str[i]))...
728x90