This chapter discusses characters, the one basic data type we've so far ignored. As with integers and reals, we study how to create character constants and define character variables, and we examine the range of values they can hold and present several different ways to read and print them. As part of this discussion, we introduce C's library functions for efficient character-at-a-time input and output and for testing whether a character falls into a particular class, such as uppercase or lowercase. Along the way, we'll also study what happens when we convert back and forth between characters and integers and discover that characters are little more than a special type of integer. The chapter concludes by extending the previous chapter's base conversion program to handle conversions from any base to any other base.
Jump to: [Previous Chapter | Next Chapter]
C ���α׷��� �⺻������ ���� ǥ�� ������� �����޴´�.
�̷��� ǥ�� ������� file�� ���� ��ȯ�� �����ϴ�.
���� �Է� : int getchar(void) - stdin���� �� ���� �Է�
���� ��� : int putchar(int) - stdout���� �� ���� ���
char ch; ch = getchar(); i = ch - '0'; if (ch >= '0' && ch <= '9') . . . // ch�� ���� '0'���� '9' ���� if (ch >= 'A' && ch <= 'Z') . . . // ch�� ���빮�� 'A'���� 'Z' ���� if (ch >= 'a' && ch <= 'z') . . . // // ch�� ���ҹ��� 'a'���� 'z' ���� for (ch = 'A'; ch <= 'Z'; ch++) putchar(ch); for (i = 0, ch = 'a'; i < 26; i = i + 1) putchar(ch + i);
������ �ڷῡ ���� ���Ǵ� operation���� <ctype.h>��
���ǵǾ� �ִ�.
islower(ch) | ch�� �ҹ��ڸ� TRUE |
isupper(ch) | ch�� �빮�ڸ� TRUE |
isalpha(ch) | ch�� alphabet�̸� TRUE |
isdigit(ch) | ch�� ���ڸ� TRUE |
isalnum(ch) | ch�� alphabet �Ǵ� digit�̸� TRUE |
ispunct(ch) | ch�� punctuation symbol�̸� TRUE |
isspace(ch) | ch�� white space(' ', '\t', '\n', '\f', '\v')�� TRUE |
tolower(ch) | ch�� �ҹ��ڷ� ��ȯ |
toupper(ch) | ch�� �빮�ڷ� ��ȯ |
Standard I/O�κ����� ������� file �Ǵ� �� ���μ����� ������� ��ȯ
�Է��� �� �˻�� EOF (End Of File) ���ڷ� ��. (stdio.h�� ����)
while ((ch = getchar()) != EOF) putchar(ch);
EOF ���� �Է��� control-'Z' ('Ctrl' key�� 'z' key�� ���ÿ� ����)
�� ���α׷��� �ۼ��ϰ� ���� È�Ϸ� ����� ��ȯ�� �˻��϶�.
75 36 10���� 75�� 36���� ���� 23 71 36 10���� 71�� 36���� ���� 1z 0 0
abc def ghi abc def ghi kkk mmm ggg kkk mmm ggg Ctrl-Z �� 6 �ܾ�