나의 작은 valley

[C언어] ctype.h 문자 분류 함수 본문

Computer Science/[C언어] 문법 정리

[C언어] ctype.h 문자 분류 함수

붕옥 아이젠 2022. 9. 14. 09:56
728x90

https://www.tutorialspoint.com/c_standard_library/ctype_h.htm

 

C Library - <ctype.h>

C Library - The ctype.h header file of the C Standard Library declares several functions that are useful for testing and mapping characters. All the functions accepts int as a parameter, whose value must be EOF or representable as an unsigned char. All the

www.tutorialspoint.com

 

위의 사이트에서 ctype.h 라이브러리에 있는 다양한 문자 분류 함수들을 볼 수 있다.

 

그 중 toupper()와 islower()을 사용하여 대문자를 소문자로, 소문자를 대문자로 바꾸는 코드를 짜보았다.

 

#include <stdio.h>	// getchar(), putchar()
#include <ctype.h>
int main()
{
	char ch;

	while ((ch= getchar()) != '\n')
	{
		if (islower(ch))	// && == and, 논리연산자
			ch = toupper(ch);
		else if (isupper(ch))
			ch = tolower(ch);

		putchar(ch);
	}

	putchar(ch);

	return 0;
}

 

 

728x90
Comments