Prev Next
C ctype.h library functions:
All C inbuilt functions which are declared in ctype.h header file are given below. The source code for ctype.h header file is also given below for your reference.
List of inbuilt C functions in ctype.h file:
- “ctype.h” header file support all the below functions in C language. Click on each function name below for detail description and example programs.
Functions | Description |
isalpha() | checks whether character is alphabetic |
isdigit() | checks whether character is digit |
isalnum() | Checks whether character is alphanumeric |
isspace() | Checks whether character is space |
islower() | Checks whether character is lower case |
isupper() | Checks whether character is upper case |
isxdigit() | Checks whether character is hexadecimal |
iscntrl() | Checks whether character is a control character |
isprint() | Checks whether character is a printable character |
ispunct() | Checks whether character is a punctuation |
isgraph() | Checks whether character is a graphical character |
tolower() | Checks whether character is alphabetic & converts to lower case |
toupper() | Checks whether character is alphabetic & converts to upper case |
Source code for ctype.h header file:
Please find the source code for ctype.h header file below. This code is taken from DevC++ compiler files for your reference.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 |
/* * ctype.h * This file has no copyright assigned and is placed in the Public Domain. * This file is a part of the mingw-runtime package. * No warranty is given; refer to the file DISCLAIMER within the package. * * Functions for testing character types and converting characters. * */ #ifndef _CTYPE_H_ #define _CTYPE_H_ /* All the headers include this file. */ #include <_mingw.h> #define __need_wchar_t #define __need_wint_t #ifndef RC_INVOKED #include <stddef.h> #endif /* Not RC_INVOKED */ /* * The following flags are used to tell iswctype and _isctype what character * types you are looking for. */ #define _UPPER 0x0001 #define _LOWER 0x0002 #define _DIGIT 0x0004 #define _SPACE 0x0008 /* HT LF VT FF CR SP */ #define _PUNCT 0x0010 #define _CONTROL 0x0020 #define _BLANK 0x0040 /* this is SP only, not SP and HT as in C99 */ #define _HEX 0x0080 #define _LEADBYTE 0x8000 #define _ALPHA 0x0103 #ifndef RC_INVOKED #ifdef __cplusplus extern "C" { #endif _CRTIMP int __cdecl isalnum(int); _CRTIMP int __cdecl isalpha(int); _CRTIMP int __cdecl iscntrl(int); _CRTIMP int __cdecl isdigit(int); _CRTIMP int __cdecl isgraph(int); _CRTIMP int __cdecl islower(int); _CRTIMP int __cdecl isprint(int); _CRTIMP int __cdecl ispunct(int); _CRTIMP int __cdecl isspace(int); _CRTIMP int __cdecl isupper(int); _CRTIMP int __cdecl isxdigit(int); #ifndef __STRICT_ANSI__ _CRTIMP int __cdecl _isctype (int, int); #endif /* These are the ANSI versions, with correct checking of argument */ _CRTIMP int __cdecl tolower(int); _CRTIMP int __cdecl toupper(int); /* * NOTE: The above are not old name type wrappers, but functions exported * explicitly by MSVCRT/CRTDLL. However, underscored versions are also * exported. */ #ifndef __STRICT_ANSI__ /* * These are the cheap non-std versions: The return values are undefined * if the argument is not ASCII char or is not of appropriate case */ _CRTIMP int __cdecl _tolower(int); _CRTIMP int __cdecl _toupper(int); #endif /* Also defined in stdlib.h */ #ifndef MB_CUR_MAX #ifdef __DECLSPEC_SUPPORTED # ifdef __MSVCRT__ # define MB_CUR_MAX __mb_cur_max __MINGW_IMPORT int __mb_cur_max; # else /* not __MSVCRT */ # define MB_CUR_MAX __mb_cur_max_dll __MINGW_IMPORT int __mb_cur_max_dll; # endif /* not __MSVCRT */ #else /* ! __DECLSPEC_SUPPORTED */ # ifdef __MSVCRT__ extern int* _imp____mbcur_max; # define MB_CUR_MAX (*_imp____mb_cur_max) # else /* not __MSVCRT */ extern int* _imp____mbcur_max_dll; # define MB_CUR_MAX (*_imp____mb_cur_max_dll) # endif /* not __MSVCRT */ #endif /* __DECLSPEC_SUPPORTED */ #endif /* MB_CUR_MAX */ #ifdef __DECLSPEC_SUPPORTED __MINGW_IMPORT unsigned short _ctype[]; # ifdef __MSVCRT__ __MINGW_IMPORT unsigned short* _pctype; # else /* CRTDLL */ __MINGW_IMPORT unsigned short* _pctype_dll; # define _pctype _pctype_dll # endif #else /* __DECLSPEC_SUPPORTED */ extern unsigned short** _imp___ctype; #define _ctype (*_imp___ctype) # ifdef __MSVCRT__ extern unsigned short** _imp___pctype; # define _pctype (*_imp___pctype) # else /* CRTDLL */ extern unsigned short** _imp___pctype_dll; # define _pctype (*_imp___pctype_dll) # endif /* CRTDLL */ #endif /* __DECLSPEC_SUPPORTED */ /* * Use inlines here rather than macros, because macros will upset * C++ usage (eg, ::isalnum), and so usually get undefined * * According to standard for SB chars, these function are defined only * for input values representable by unsigned char or EOF. * Thus, there is no range test. * This reproduces behaviour of MSVCRT.dll lib implemention for SB chars. * * If no MB char support is needed, these can be simplified even * more by command line define -DMB_CUR_MAX=1. The compiler will then * optimise away the constant condition. */ #if ! (defined (__NO_INLINE__) || defined (__NO_CTYPE_INLINES) \ || defined (__STRICT_ANSI__ )) /* use simple lookup if SB locale, else _isctype() */ #define __ISCTYPE(c, mask) (MB_CUR_MAX == 1 ? (_pctype[c] & mask) : _isctype(c, mask)) __CRT_INLINE int __cdecl isalnum(int c) {return __ISCTYPE(c, (_ALPHA|_DIGIT));} __CRT_INLINE int __cdecl isalpha(int c) {return __ISCTYPE(c, _ALPHA);} __CRT_INLINE int __cdecl iscntrl(int c) {return __ISCTYPE(c, _CONTROL);} __CRT_INLINE int __cdecl isdigit(int c) {return __ISCTYPE(c, _DIGIT);} __CRT_INLINE int __cdecl isgraph(int c) {return __ISCTYPE(c, (_PUNCT|_ALPHA|_DIGIT));} __CRT_INLINE int __cdecl islower(int c) {return __ISCTYPE(c, _LOWER);} __CRT_INLINE int __cdecl isprint(int c) {return __ISCTYPE(c, (_BLANK|_PUNCT|_ALPHA|_DIGIT));} __CRT_INLINE int __cdecl ispunct(int c) {return __ISCTYPE(c, _PUNCT);} __CRT_INLINE int __cdecl isspace(int c) {return __ISCTYPE(c, _SPACE);} __CRT_INLINE int __cdecl isupper(int c) {return __ISCTYPE(c, _UPPER);} __CRT_INLINE int __cdecl isxdigit(int c) {return __ISCTYPE(c, _HEX);} /* these reproduce behaviour of lib underscored versions */ __CRT_INLINE int __cdecl _tolower(int c) {return ( c -'A'+'a');} __CRT_INLINE int __cdecl _toupper(int c) {return ( c -'a'+'A');} /* TODO? Is it worth inlining ANSI tolower, toupper? Probably only if we only want C-locale. */ #endif /* _NO_CTYPE_INLINES */ /* Wide character equivalents */ #ifndef WEOF #define WEOF (wchar_t)(0xFFFF) #endif #ifndef _WCTYPE_T_DEFINED typedef wchar_t wctype_t; #define _WCTYPE_T_DEFINED #endif _CRTIMP int __cdecl iswalnum(wint_t); _CRTIMP int __cdecl iswalpha(wint_t); _CRTIMP int __cdecl iswascii(wint_t); _CRTIMP int __cdecl iswcntrl(wint_t); _CRTIMP int __cdecl iswctype(wint_t, wctype_t); _CRTIMP int __cdecl is_wctype(wint_t, wctype_t); /* Obsolete! */ _CRTIMP int __cdecl iswdigit(wint_t); _CRTIMP int __cdecl iswgraph(wint_t); _CRTIMP int __cdecl iswlower(wint_t); _CRTIMP int __cdecl iswprint(wint_t); _CRTIMP int __cdecl iswpunct(wint_t); _CRTIMP int __cdecl iswspace(wint_t); _CRTIMP int __cdecl iswupper(wint_t); _CRTIMP int __cdecl iswxdigit(wint_t); _CRTIMP wchar_t __cdecl towlower(wchar_t); _CRTIMP wchar_t __cdecl towupper(wchar_t); _CRTIMP int __cdecl isleadbyte (int); /* Also in wctype.h */ #if ! (defined (__NO_INLINE__) || defined(__NO_CTYPE_INLINES) \ || defined(__WCTYPE_INLINES_DEFINED)) #define __WCTYPE_INLINES_DEFINED __CRT_INLINE int __cdecl iswalnum(wint_t wc) {return (iswctype(wc,_ALPHA|_DIGIT));} __CRT_INLINE int __cdecl iswalpha(wint_t wc) {return (iswctype(wc,_ALPHA));} __CRT_INLINE int __cdecl iswascii(wint_t wc) {return ((wc & ~0x7F) ==0);} __CRT_INLINE int __cdecl iswcntrl(wint_t wc) {return (iswctype(wc,_CONTROL));} __CRT_INLINE int __cdecl iswdigit(wint_t wc) {return (iswctype(wc,_DIGIT));} __CRT_INLINE int __cdecl iswgraph(wint_t wc) {return (iswctype(wc,_PUNCT|_ALPHA|_DIGIT));} __CRT_INLINE int __cdecl iswlower(wint_t wc) {return (iswctype(wc,_LOWER));} __CRT_INLINE int __cdecl iswprint(wint_t wc) {return (iswctype(wc,_BLANK|_PUNCT|_ALPHA|_DIGIT));} __CRT_INLINE int __cdecl iswpunct(wint_t wc) {return (iswctype(wc,_PUNCT));} __CRT_INLINE int __cdecl iswspace(wint_t wc) {return (iswctype(wc,_SPACE));} __CRT_INLINE int __cdecl iswupper(wint_t wc) {return (iswctype(wc,_UPPER));} __CRT_INLINE int __cdecl iswxdigit(wint_t wc) {return (iswctype(wc,_HEX));} __CRT_INLINE int __cdecl isleadbyte(int c) {return (_pctype[(unsigned char)(c)] & _LEADBYTE);} #endif /* !(defined(__NO_CTYPE_INLINES) || defined(__WCTYPE_INLINES_DEFINED)) */ #ifndef __STRICT_ANSI__ int __cdecl __isascii (int); int __cdecl __toascii (int); int __cdecl __iscsymf (int); /* Valid first character in C symbol */ int __cdecl __iscsym (int); /* Valid character in C symbol (after first) */ #if !(defined (__NO_INLINE__) || defined (__NO_CTYPE_INLINES)) __CRT_INLINE int __cdecl __isascii(int c) {return ((c & ~0x7F) == 0);} __CRT_INLINE int __cdecl __toascii(int c) {return (c & 0x7F);} __CRT_INLINE int __cdecl __iscsymf(int c) {return (isalpha(c) || (c == '_'));} __CRT_INLINE int __cdecl __iscsym(int c) {return (isalnum(c) || (c == '_'));} #endif /* __NO_CTYPE_INLINES */ #ifndef _NO_OLDNAMES /* Not _CRTIMP */ int __cdecl isascii (int); int __cdecl toascii (int); int __cdecl iscsymf (int); int __cdecl iscsym (int); #endif /* Not _NO_OLDNAMES */ #endif /* Not __STRICT_ANSI__ */ #ifdef __cplusplus } #endif #endif /* Not RC_INVOKED */ #endif /* Not _CTYPE_H_ */ |