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

The Standard C Library for Linux:ctype.h

 2008-03-08 12:39:38 来源:WEB开发网 闂傚倸鍊搁崐椋庢濮橆兗缂氱憸宥堢亱闂佸湱铏庨崰鏍不椤栫偞鐓ラ柣鏇炲€圭€氾拷闂傚倸鍊搁崐椋庣矆娓氣偓楠炲鏁撻悩鎻掔€梺姹囧灩閻忔艾鐣烽弻銉︾厵闁规鍠栭。濂告煕鎼达紕校闁靛洤瀚伴獮鎺楀箣濠靛啫浜鹃柣銏⑶圭壕濠氭煙閻愵剚鐏辨俊鎻掔墛缁绘盯宕卞Δ鍐冣剝绻涘畝濠佺敖缂佽鲸鎹囧畷鎺戭潩閹典焦鐎搁梻浣烘嚀閸ゆ牠骞忛敓锟�婵犵數濮烽弫鍛婃叏椤撱垹绠柛鎰靛枛瀹告繃銇勯幘瀵哥畼闁硅娲熷缁樼瑹閳ь剙岣胯鐓ら柕鍫濇偪濞差亜惟闁宠桨鑳堕崝锕€顪冮妶鍡楃瑐闁煎啿鐖奸崺濠囧即閵忥紕鍘梺鎼炲劗閺呮稒绂掕缁辨帗娼忛埡浣锋闂佽桨鐒﹂幑鍥极閹剧粯鏅搁柨鐕傛嫹闂傚倸鍊搁崐椋庢濮橆兗缂氱憸宥堢亱闂佸湱铏庨崰鏍不椤栫偞鐓ラ柣鏇炲€圭€氾拷  闂傚倸鍊搁崐鐑芥嚄閼哥數浠氱紓鍌欒兌缁垶銆冮崨鏉戠厺鐎广儱顦崡鎶芥煏韫囨洖校闁诲寒鍓熷铏圭磼濡搫顫岄梺鍦拡閸嬪棝鎯€椤忓浂妯勯梺鍝勬湰濞叉ḿ鎹㈠┑濠勭杸闁哄洨濮烽悰銉╂⒒娴e搫甯跺鐟帮攻缁傚秴饪伴崼姘e亾閺冨牆绀冩い蹇庣娴滈箖鏌ㄥ┑鍡涱€楀褜鍠栭湁闁绘ɑ鐟ョ€氼喚绮绘ィ鍐╃厱妞ゆ劑鍊曢弸搴ㄦ煟韫囧鍔滈柕鍥у瀵潙螣閸濆嫬袝婵$偑鍊戦崹娲偡閳哄懎绠栭柍鈺佸暞閸庣喖鏌曢崶褍绨婚柟鍑ゆ嫹
核心提示: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)
赞助商链接