Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 |
Tags
- 정수론
- programmers
- 따라하며 배우는 C언어
- 인프런
- udemy
- DP
- 따라하면서 배우는 C언어
- C언어
- graph
- web
- BOJ
- Algospot
- php
- BFS
- Python
- 따배씨
- server
- C
- sorting
- dfs
- Algorithm
- 생활코딩
- 종만북
- JavaScript
- greedy
- Cleancode
- Math
- String
- 백준
- BASIC
Archives
- Today
- Total
몽상실현개발주의
[따배씨] 7.8 단어 세기 예제 본문
따배씨 - 따라하며 배우는 C언어
7강 분기
7.8 단어 세기 예제
#include <stdio.h>
#include <ctype.h>
#include <stdbool.h>
#define STOP '.'
int main(){
char ch;
unsigned char_cnt = 0;
unsigned world_cnt = 0;
unsigned line_cnt = 1;
bool world_flag = false;
bool line_flag = false;
printf("Enter text :\n");
while((ch = getchar()) != STOP)
{
// character count
if (!isspace(ch)){
char_cnt++;
}
// world count
if (!isspace(ch) && !world_flag)
{
world_cnt++;
world_flag = true;
}
if (isspace(ch)){
world_flag = false;
}
// line count
if (!isspace(ch) && !line_flag)
{
line_cnt++;
line_flag = true;
}
if (ch == '\n')
{
line_flag = false;
}
}
printf("Characters = %u, Worlds = %u, Lines = %u\n", char_cnt, world_cnt, line_cnt);
return 0;
}
- Character Count
- 입력이 공백이 아닐시 무조건 Count
- World Count
- 새로운 단어의 시작시, Count && world_flag = true
- world_flag == true 상태에서 공백 입력시, 단어 입력 종료
- world_flag = false
- Line Count
- '\n' 입력 == 다음줄로 넘어갈 시, line_flag = false
- 공백이 입력 && line_flag == false 일 때, 새로운줄 시작으로 판단
이 글의 모든 사진과 내용의 출처는 홍정모 교수님께 있음을 알려드립니다.
http://blog.naver.com/atelierjpro
실리콘 밸리의 프로그래머 : 네이버 블로그
안녕하세요! 홍정모 블로그에 오신 것을 환영합니다. 주로 프로그래밍 관련 메모 용도로 사용합니다. 강의 수강하시는 분들은 홍정모 연구소 카페로 오세요.
blog.naver.com
http://www.inflearn.com/course/following-c
홍정모의 따라하며 배우는 C언어 - 인프런 | 강의
'따배씨++'의 성원에 힘입어 새롭게 개발된 C 언어로 시작하는 프로그래밍 입문 강의입니다. '따배씨'와 함께 프로그래밍 인생을 업그레이드 해보세요., 따라하며 배우는 C언어 '따배씨++'의 성원
www.inflearn.com
'Language > C' 카테고리의 다른 글
[따배씨] 7.10 루프 도우미 continue 와 break (0) | 2021.05.24 |
---|---|
[따배씨] 7.9 조건 연산자 (0) | 2021.05.24 |
[따배씨] 7.7 논리 연산자 (0) | 2021.05.24 |
[따배씨] 7.6 소수 판단 예제 (0) | 2021.05.24 |
[따배씨] 7.4 다중선택 else if ~ 7.5 else 와 if 짝짓기 (0) | 2021.05.24 |
Comments