055. 문자열 입력받기(gets)055. 문자열 입력받기(gets)

Posted at 2011. 1. 30. 17:43 | Posted in Computer/초보자를 위한 C 언어 300제
#include <stdio.h>

int count( char *str );

void main( void )
{
	char string[100];
	char *ret;

	ret = gets( string );

	if( ret != NULL )
	{
		printf( "문자 'a'의 갯수는 %d개입니다.", count(string) );
	}
}

int count( char *str )
{
	int cnt = 0;

	while( *str != (int)NULL )
	{
		if( *str++ == 'a' ) cnt++;
	}

	return cnt;
}
//