Desc :

int isalnum( int c );

c - 비교대상 문자

 

문자 및 숫자를 동시에 판별

대문자, 소문자, 숫자인경우 --> 1 true

아닌경우 --> 0 false

 


Source Code :

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

void main()
{
	char *string = "Cat 1 Car 2 Cow 3,...";
	char buffer[100] = { 0, };
	int cnt = 0;

	while (*string)	// null이 아닌동안 반복
	{
		if (isalnum(*string))	// 주소가 가리키는 값 하나  
		{
			buffer[cnt++] = *string;	// --> 문자나 숫자면 buffer에 저장
		}

		string++;	// 다음 번지
	}

	puts(buffer);	// 문자 및 숫자가 추출된 문자열

}

 


Result :

 

공백만 제거되어 출력되었다

 

+ Recent posts