开发学院软件开发C++ The Standard C Library for Linux:ctype.h 阅读

The Standard C Library for Linux:ctype.h

 2008-03-08 12:39:38 来源:WEB开发网   
核心提示:Part Four: <ctype.h> Character Handling By James M. Rogers The last article was on

  Part Four: <ctype.h> Character Handling
By James M. Rogers

--------------------------------------------------------------------------------

The last article was on <stdio.h> Input and Output. This article is on <ctype.h> character handling.

Character handling allows us to clasify 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.

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.

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.

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 .
This program can be used as a cgi-bin script and is a demonstration of the flexibility of the c language.


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.

Character Handling


#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 returns true if the character is in the range of A-Z or a-z.
isalnum returns true if the character is in the range of A-Z or a-z or 0-9.

isdigit returns true if the character is in the range of 0-9.

isxdigit returns true if the character is in the range of 0-9 or a-f or A-F.

iscntrl returns true if the character is in the set (FF, NL, CR, HT, VT, BEL or BS).


isspace returns true if the character is in the set (space, FF, NL, CR, HT or VT).

ispunct returns true if the character is a nonalnum, nonspace and noncntrl.

isgraph returns true if the character isalnum or ispunct.

isprint returns true if the character isspace or isgraph.

islower returns true if the character is in the range of a-z.

isupper returns true if the character is in the range of A-Z.

tolower if isupper return the lowercase character otherwise return the character.

toupper if islower return the uppercase character otherwise return the character.

From:www.linuxgazette.com

Tags:The Standard Library

编辑录入:爽爽 [复制链接] [打 印]
[]
  • 好
  • 好的评价 如果觉得好,就请您
      0%(0)
  • 差
  • 差的评价 如果觉得差,就请您
      0%(0)
赞助商链接