在網路上看到了一些關於 ctype.h 一些 macro,這裡做些摘錄

 #define is_digit(c)     ((c)>='0' && (c)<='9')
 #define is_digit(c)     ((unsigned)(c) - '0' <= 9)
 #define is_alpha(c)     (((c) < CTLESC || (c) > CTLENDARI) && isalpha((unsigned char) (c)))
 #define is_name(c)      (((c) < CTLESC || (c) > CTLENDARI) && ((c) == '_' || isalpha((unsigned char) (c))))
 #define is_in_name(c)   (((c) < CTLESC || (c) > CTLENDARI) && ((c) == '_' || isalnum((unsigned char) (c))))
 #define is_special(c)   ((is_type+SYNBASE)[c] & (ISSPECL|ISDIGIT))
 #define is_special(c)   (is_digit(c)||c=='!'||c=='#'||c=='$'||c=='*'||c=='-')
 #define digit_val(c)    ((c) - '0')

關於一些 NULL, BEL 之輸入,可在這個網站找到相關說明,截錄如下

CharOctDecHexControl-KeyControl Action
NUL 0 0 0 ^@ NULl character
SOH 1 1 1 ^A Start Of Heading
STX 2 2 2 ^B Start of TeXt
ETX 3 3 3 ^C End of TeXt
EOT 4 4 4 ^D End Of Transmission
ENQ 5 5 5 ^E ENQuiry
ACK 6 6 6 ^F ACKnowledge
BEL 7 7 7 ^G BELl, rings terminal bell
BS 10 8 8 ^H BackSpace (non-destructive)
HT 11 9 9 ^I Horizontal Tab (move to next tab position)
LF 12 10 a ^J Line Feed
VT 13 11 b ^K Vertical Tab
FF 14 12 c ^L Form Feed
CR 15 13 d ^M Carriage Return
SO 16 14 e ^N Shift Out
SI 17 15 f ^O Shift In
DLE 20 16 10 ^P Data Link Escape
DC1 21 17 11 ^Q Device Control 1, normally XON
DC2 22 18 12 ^R Device Control 2
DC3 23 19 13 ^S Device Control 3, normally XOFF
DC4 24 20 14 ^T Device Control 4
NAK 25 21 15 ^U Negative AcKnowledge
SYN 26 22 16 ^V SYNchronous idle
ETB 27 23 17 ^W End Transmission Block
CAN 30 24 18 ^X CANcel line
EM 31 25 19 ^Y End of Medium
SUB 32 26 1a ^Z SUBstitute
ESC 33 27 1b ^[ ESCape
FS 34 28 1c ^\ File Separator
GS 35 29 1d ^] Group Separator
RS 36 30 1e ^^ Record Separator
US 37 31 1f ^_ Unit Separator

另外有些心得也放上來

0. 範圍

A~Z: 41H~5AH (0100 0001~0101 1010)
a~z: 61H~7AH (0110 0001~0111 1010)
0~9: 30H~39H (0011 0000~0011 1001)

1. 大寫轉小寫

#define BITMASK 0x20
char ch = 'A';
ch |= BITMASK

 2. 小寫轉大寫

#define BITMASK (~(0x20))
char ch = 'a';
ch &= BITMASK

 3. 字元'0'~'9' 轉整數

int x;
char ch;
x=ch & 0x0F;
arrow
arrow
    全站熱搜

    edisonx 發表在 痞客邦 留言(0) 人氣()