C語言isspace()函數(shù):判斷字符是否為空白字符
頭文件:
#include <ctype.h>
定義函數(shù):
int isspace(int c);
函數(shù)說明:檢查參數(shù)c是否為空格字符,也就是判斷是否為空格(' ')、定位字符(' /t ')、CR(' /r ')、換行(' /n ')、垂直定位字符(' /v ')或翻頁(' /f ')的情況。
返回值:若參數(shù)c 為空白字符,則返回非 0,否則返回 0。
附加說明:此為宏定義,非真正函數(shù)。
范例:將字符串str[]中內(nèi)含的空格字符找出,并顯示空格字符的ASCII 碼。
#include <ctype.h>main(){ char str[] = "123c @# FD/tsP[e?/n"; int i; for(i = 0; str[i] != 0; i++) if(isspace(str[i])) printf("str[%d] is a white-space character:%d/n", i, str[i]);}
執(zhí)行結(jié)果:
str[4] is a white-space character:32str[7] is a white-space character:32str[10] is a white-space character:9 // /tstr[16] is a white-space character:10 // /t
C語言ispunct()函數(shù):判斷字符是否為標(biāo)點符號或特殊字符
頭文件:
#inlude <ctype.h>
ispunct() 函數(shù)用來檢測一個字符是否為標(biāo)點符號或特殊字符,其原型為:
int ispunct(int c);
【參數(shù)】c 為需要檢測的字符。
【返回值】若 c 為標(biāo)點符號或特殊符號(非空格、非數(shù)字和非英文字母)返回非 0 值,否則返回 0。
注意,此為宏定義,非真正函數(shù)。
【實例】列出字符串str 中的標(biāo)點符號或特殊符號。
#include <stdio.h>#include <ctype.h>int main (){ int i=0; int cx=0; char str[]="Hello, welcome!"; while (str[i]) { if (ispunct(str[i])) cx++; i++; } printf ("Sentence contains %d punctuation characters./n", cx); return 0;}
輸出結(jié)果:
Sentence contains 2 punctuation characters.
|
新聞熱點
疑難解答
圖片精選