728x90
반응형

코드

더보기
# include <stdio.h>

#define PREIOD '.'
int main(){
	
	char ch;
	
	int Characters=0;  // 문자의 개수 저장공간 변수. 
	int Words=0; 	   // 공백의 개수 저장공간 변수. 
	int Lines=0;	   // 줄바꿈의 개수 저장공간 변수. 
	
	printf("Enter text : ");
	while((ch =getchar())!=PREIOD){
		if(ch =='\n')
			Lines++;
		if(ch ==' ')
			Words++;
		Characters++;
	}	
	printf("Characters = %d, Words = %d, Lines = %d",(Characters-Words-Lines),Words,Lines);
}

[그림1] C언어 단어 세기 예제 출력

 

728x90
반응형
  • 네이버 블러그 공유하기
  • 네이버 밴드에 공유하기
  • 페이스북 공유하기
  • 카카오스토리 공유하기