#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <ctype.h>
#include <stdbool.h>
#define STOP '.'
int main()
{
char c;
int n_chars = 0; // number of non-space characters
int n_lines = 0;
int n_words = 0;
bool word_flag = false;
bool line_flag = false;
printf("Enter text : \n");
while ((c = getchar()) != STOP)
{
if (!isspace(c)) // count non-space characters .. 입력받은 글자가 빈칸이 아니라면
n_chars++;
if (!isspace(c) && !line_flag) // 빈칸이 아니고 line_flag 가 false 라면
{
n_lines++;
line_flag = true;
}
if (c == '\n')
line_flag = false;
if (!isspace(c) && !word_flag)
{
n_words++;
word_flag = true;
}
if (isspace(c))
word_flag = false;
}
printf("Characters = %d, Words = %d, Lines = %d\n", n_chars, n_words, n_lines);
return 0;
}
제가 이 코드에서 if (!isspace(c) && !line_flag)
부터 이해가 안됩니다
디버깅을 해봐도 이해가 잘 안됩니다.
line_flag
를 false
로 초기화를 했는데 if (!isspace(c) && !line_flag)
문에서 !line_flag
는 false
인가요 true
인가요? 다른 예제로 변형해서 만드는건 성공했는데 이 예제 자체는 이해가 안됩니다. 도와주세요.