Computer/초보자를 위한 C 언어 300제
055. 문자열 입력받기(gets)
Theo Kim
2011. 1. 30. 17:43
#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; }