Linux 版 (精华区)
发信人: howdoit (教练让我上场!!!), 信区: Linux
标 题: Linux标准C库第四部分:<ctype.h>字符处理
发信站: 哈工大紫丁香 (Tue May 18 09:07:07 1999), 转信
《Linux公报》……让Linux更富魅力!
Linux标准C库
第四部分:<ctype.h> 字符处理
By James M. Rogers 翻译:帆
The last article was on <stdio.h> Input and Output. This
article is on <ctype.h> character handling.
上一篇文章是关于<stdio.h>的输入输出部分。这篇文章介绍
<ctype.h>的字符处理。
Character handling allows us to classify characters as alpha,
digit, hexdigit, whitespace, printable, lowercase, uppercase,
punctuation and to map to and from the upper and lowercase
alphabets. Most importantly <ctype.h> implements these
functions in a non-system dependent way.
字符操作可以让我们把字符分成字母,数字,十六进制数,空格,制
表符,小写,答谢,标点符号,和大小写间的转换。最重要的是
<ctype.h>使用系统无关的方法实现了这些功能。
If you write your program assuming that every computer is an
ASCII computer you will have trouble porting your program to
non ASCII machines. If you write your character handling
functions in terms of these functions your program will be
much more portable to other platforms.
如果你写程序的时候假设每台计算机都是ASCII计算机的话,那当这个
程序移植到其他非ASCII计算机的时候将会出现问题。而如果你使用这
些函数来写程序,它对其他平台的移植性就会增强很多。
I am assuming a knowledge of c programming on the part of the
reader. There is no guarantee of accuracy in any of this
information nor suitability for any purpose.
我假设这一章的读者有c编程的知识。这篇文档的正确性我也不做保
证。
The program example that I will do this month will go thru
the entire 8bit ASCII range and tell us to which classes any
one chacter belongs. The example is rogers_example04.c. The
output the program generates will be an html document and the
run from my system is rogers_example04.html .
在这个程序例子中,我将把整个8位ASCII表遍历一遍,并且分出来每
个字符都属于那一类。这是程序:rogers_example04.c。程序将输出
一个html文档,在这里rogers_example04.html。
This program can be used as a cgi-bin script and is a
demonstration of the flexibility of the c language.
这个程序可以作为一个cgi-bin脚本运行,这一点可以证明c语言的灵
活性。
As always, if you see an error in my documentation please
tell me and I will correct myself in a later document. See
corrections at end of the document to review corrections to
the previous articles.
如果你在这个文档里发现了错误请告诉我,我会在以后的文档里纠正
错误的。看本文最后的勘误,那里有前几期的文章订正。
字符处理
#include <ctype.h>
int isalpha(int c);
int isalnum(int c);
int isdigit(int c);
int isxdigit(int c);
int iscntrl(int c);
int isspace(int c);
int ispunct(int c);
int isgraph(int c);
int isprint(int c);
int islower(int c);
int isupper(int c);
int tolower(int c);
int toupper(int c);
isalpha 如果字符的范围在A-Z 或 a-z之间返回true
isalnum 如果字符的范围在A-Z 或 a-z 或 0-9之间返回true
isdigit 如果字符的范围在0-9 之间返回true
isxdigit 如果字符的范围在0-9 或 a-f或A-F之间返回true
iscntrl 如果字符在这个集合里返回true:(FF, NL, CR, HT, VT,
BEL or BS)
isspace 如果字符在这个集合里返回truet:(space, FF, NL, CR, HT
or VT).
ispunct returns 如果字符是非数字、非空格和非控制字符,则返回
true
isgraph 如果isalnum或ispunct返回真,这个函数就返回真
isprint 如果字符是isspace或isgraph,则返回true
islower 如果字符的范围在A-Z 之间返回true
tolower 如果isupper为真,则本函数返回它的小写字母,否则返回字
符本身
toupper 如果islower为真,则本函数返回它的大写字母,否则返回字
符本身
参考数目:
The ANSI C Programming Language, Second Edition, Brian W.
Kernighan, Dennis M. Ritchie, Printice Hall Software Series,
1988
The Standard C Library, P. J. Plauger, Printice Hall P T R,
1992
The Standard C Library, Parts 1, 2, and 3, Chuck Allison,
C/C++ Users Journal, January, February, March 1995
CTYPE(3), BSD MANPAGE, Linux Programmer's Manual, 29 November
1993
Previous "The Standard C Library for Linux" Articles
The Standard C Library for Linux, Part One, James M. Rogers,
January 1998
The Standard C Library for Linux, Part Two, James M. Rogers,
July 1998
The Standard C Library for Linux, Part Three, James M.
Rogers, August 1998
版权所有 (C) 1999 NJLUG
出版于第38期《Linux公报》1999年3月 中文版第五期
--
☆ 来源:.哈工大紫丁香 bbs.hit.edu.cn.[FROM: bin@mtlab.hit.edu.cn]
Powered by KBS BBS 2.0 (http://dev.kcn.cn)
页面执行时间:5.474毫秒