我想確定我的字符串中的每個字符是否是字母數字。我的編譯器沒有isalnum函數。isalnum等效使用#define
我的函數如下,my_struct有一個大小爲6的字符數組(uint8 bom_pn [6])....並且是uint8是char。
boolean myfunc(my_struct * lh)
{
ret = (isalphanum(lh->bom_pn) && isalphanum(lh->bom_pn + 1) &&
isalphanum(lh->bom_pn + 2) && isalphanum(lh->bom_pn + 3) &&
isalphanum(lh->bom_pn + 4) && isalphanum(lh->bom_pn + 5));
}
我的宏定義如下:
#define isalphanum(c) ((c >= '0' && c <= '9') || \
(c >= 'A' && c <= 'Z') || \
(c >= 'a' && c <= 'z'))
上述引發錯誤 「操作數類型是不兼容的(」 UINT8 * 「和」 INT 「)」
如果我改變我的定義到下面,我的代碼編譯,我得到警告。
#define isalphanum(c) (((uint8)c >= '0' && (uint8)c <= '9') || \
((uint8)c >= 'A' && (uint8)c <= 'Z') || \
((uint8)c >= 'a' && (uint8)c <= 'z'))
警告:「從指針轉換爲更小的整數」
我的問題是,我該如何正確地創建這個定義沒有警告(顯然正確檢查)。
由於
需要注意的是,超出了你的指針指向與 - 問題,你沒有處理區域設置。爲什麼你的環境沒有'ctype.h'? – geekosaur 2012-04-10 18:43:43
銖,我的意思是說回報(isal .....) – NickG 2012-04-10 18:50:27