C

[C] 094 문자가 공백, 탭문자, 개행문자인지 검사 isspace()

qkrwngus 2021. 1. 27. 21:10

Desc :

int isspace( int c );

c - 비교대상문자

 

--> 공백, 탭, 개행문자인 경우 1

 

문자열 좌우 공백 등 필요없는 문자를 제거할 때 유용하게 사용됨


Source Code :

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

void main()
{
	char *string = "This is Korea!\t\n";
	char buffer[100] = { 0, };
	int cnt = 0;

	while (*string)
	{
		if (isspace(*string))  
		{
			cnt++;

		}

		string++;
	}

	printf("공백, 탭, 개행문자의 수는 %d입니다.", cnt);
}

 


Result :