程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> C >> C語言基礎知識 >> The Standard C Library for Linux:ctype.h

The Standard C Library for Linux:ctype.h

編輯:C語言基礎知識

  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
 
  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved