|
씨_java 님이 쓰신 글 :
: 이 프로그램을 출력을 못하겠습니다.
:
: A book on C(168p)에 소스인데 출력을 못하겠습니다.
:
: 소스는 이렇습니다
ctype.h 에는
문자가 숫자인지를 검사하는 isdigit(),
영문자인지를 검사하는 isalpha()와 같은 여러가지 유용한
문자 코드의 값을 판단하는 편리한 매크로 함수가 있습니다.
isdigit()과 isalpha()를 사용하여 님의 소스를 수정하면 다음과 같습니다.
/*
* cnt_char.c
*
* count blanks, digits, letters, newlines, and others.
*/
#include <stdio.h>
#include <ctype.h>
int main(void)
{
int blank_cnt = 0, c, digit_cnt = 0,
letter_cnt = 0, nl_cnt = 0, other_cnt = 0;
while ((c = getchar()) != EOF) /* braces not necessary */
if (c == ' ')
++blank_cnt;
else if (isdigit(c))
++digit_cnt;
else if (isalpha(c))
++letter_cnt;
else if (c == '\n')
++nl_cnt;
else
+other_cnt;
printf("%10s%10s%10s%10s%10s%10s\n\n",
"blanks", "digits", "letters", "lines", "others", "total");
printf("%10d%10d%10d%10d%10d%10d\n\n",
blank_cnt, digit_cnt, letter_cnt, nl_cnt,other_cnt,
blank_cnt + digit_cnt + letter_cnt + nl_cnt + other_cnt);
return 0;
}
//---------------------------------------------------------------------------
: 한문자를 입력받아 다양한 종류의 문자를 세는 예제인데
: 실행을 하면 값을 볼수가 없습니다.(에러메세지도 없구요)
:
: 책에는 원시파일을 자료파일로 하여 다음과 같이 프로그램을 실행해라...
: cnt_char < cnt_char.c
: 어떻게 출력을 해야 하는지???
명령 프롬프트(MS-DOS 창)을 띄우신 후, 위의 명령
cnt_char < cnt_char.c
을 입력하시면 됩니다.
|