头文件 ctype.h/cctype

本文深入探讨了字符测试函数(如isalpha, isascii等)和字符映射函数(如toupper, tolower等)的功能及应用。通过具体实例,展示了如何在编程中灵活运用这些函数进行字符串操作。

1. 函数情况 主要为字符测试函数和字符映射函数。所有的函数中的参数都为一个int类型的值,返回值为int。

2. 主要函数

    字符测试函数:

    isalpha / isascii / isascii  / isspace / ispunct / isprint / isalnum  / isgraph / isdigit  /iscntrl(是否为控制字符)

    字符映射函数:

    toupper / tolower

3. c: include <ctype.h>

    c++:#include <cctype>

In file included from D:\TS_Master\TSMaster\Configuration\TOSUN\TSMaster\MiniProgram\Build\CCode7142\CCode7142Extern.cpp:7: In file included from C:\Program Files (x86)\TOSUN\TSMaster\Data\compilers\llvm_mingw_x86\bin/../include/c++/v1/vector:325: In file included from C:\Program Files (x86)\TOSUN\TSMaster\Data\compilers\llvm_mingw_x86\bin/../include/c++/v1/__format/formatter_bool.h:20: In file included from C:\Program Files (x86)\TOSUN\TSMaster\Data\compilers\llvm_mingw_x86\bin/../include/c++/v1/__format/formatter_integral.h:35: In file included from C:\Program Files (x86)\TOSUN\TSMaster\Data\compilers\llvm_mingw_x86\bin/../include/c++/v1/locale:202: In file included from C:\Program Files (x86)\TOSUN\TSMaster\Data\compilers\llvm_mingw_x86\bin/../include/c++/v1/__locale:36: C:\Program Files (x86)\TOSUN\TSMaster\Data\compilers\llvm_mingw_x86\bin/../include/c++/v1/__support/win32/locale_win32.h:95:12: error: unknown type name '_locale_t'; did you mean 'locale_t'? 95 | locale_t(_locale_t __xlocale, const char* __xlocale_str) | ^ C:\Program Files (x86)\TOSUN\TSMaster\Data\compilers\llvm_mingw_x86\bin/../include/c++/v1/__support/win32/locale_win32.h:91:7: note: 'locale_t' declared here 91 | class locale_t { | ^ C:\Program Files (x86)\TOSUN\TSMaster\Data\compilers\llvm_mingw_x86\bin/../include/c++/v1/__support/win32/locale_win32.h:140:12: error: unknown type name '_locale_t'; did you mean 'locale_t'? 140 | operator _locale_t() const { return __locale_; } | ^ C:\Program Files (x86)\TOSUN\TSMaster\Data\compilers\llvm_mingw_x86\bin/../include/c++/v1/__support/win32/locale_win32.h:91:7: note: 'locale_t' declared here 91 | class locale_t { | ^ C:\Program Files (x86)\TOSUN\TSMaster\Data\compilers\llvm_mingw_x86\bin/../include/c++/v1/__support/win32/locale_win32.h:149:3: error: unknown type name '_locale_t'; did you mean 'locale_t'? 149 | _locale_t __locale_; | ^ C:\Program Files (x86)\TOSUN\TSMaster\Data\compilers\llvm_mingw_x86\bin/../include/c++/v1/__support/win32/locale_win32.h:91:7: note: 'locale_t' declared here 91 | class locale_t { | ^ C:\Program Files (x86)\TOSUN\TSMaster\Data\compilers\llvm_mingw_x86\bin/../include/c++/v1/__support/win32/locale_win32.h:149:13: error: field has incomplete type 'locale_t' 149 | _locale_t __locale_; | ^ C:\Program Files (x86)\TOSUN\TSMaster\Data\compilers\llvm_mingw_x86\bin/../include/c++/v1/__support/win32/locale_win32.h:91:7: note: definition of 'locale_t' is not complete until the closing '}' 91 | class locale_t { | ^ C:\Program Files (x86)\TOSUN\TSMaster\Data\compilers\llvm_mingw_x86\bin/../include/c++/v1/__support/win32/locale_win32.h:199:53: error: unknown type name '_locale_t' 199 | inline _LIBCPP_HIDE_FROM_ABI int islower_l(int __c, _locale_t __loc) { return _islower_l((int)__c, __loc); } | ^ C:\Program Files (x86)\TOSUN\TSMaster\Data\compilers\llvm_mingw_x86\bin/../include/c++/v1/__support/win32/locale_win32.h:201:53: error: unknown type name '_locale_t' 201 | inline _LIBCPP_HIDE_FROM_ABI int isupper_l(int __c, _locale_t __loc) { return _isupper_l((int)__c, __loc); } | ^ C:\Program Files (x86)\TOSUN\TSMaster\Data\compilers\llvm_mingw_x86\bin/../include/c++/v1/__support/win32/locale_win32.h:233:95: error: unknown type name 'va_list' 233 | _LIBCPP_EXPORTED_FROM_ABI int vasprintf_l(char** __ret, locale_t __loc, const char* __format, va_list __ap); | ^ In file included from D:\TS_Master\TSMaster\Configuration\TOSUN\TSMaster\MiniProgram\Build\CCode7142\CCode7142Extern.cpp:7: In file included from C:\Program Files (x86)\TOSUN\TSMaster\Data\compilers\llvm_mingw_x86\bin/../include/c++/v1/vector:325: In file included from C:\Program Files (x86)\TOSUN\TSMaster\Data\compilers\llvm_mingw_x86\bin/../include/c++/v1/__format/formatter_bool.h:20: In file included from C:\Program Files (x86)\TOSUN\TSMaster\Data\compilers\llvm_mingw_x86\bin/../include/c++/v1/__format/formatter_integral.h:35: C:\Program Files (x86)\TOSUN\TSMaster\Data\compilers\llvm_mingw_x86\bin/../include/c++/v1/locale:719:68: error: use of undeclared identifier '_strtoi64_l' 719 | long long __ll = strtoll_l(__a, &__p2, __base, _LIBCPP_GET_C_LOCALE); | ^ C:\Program Files (x86)\TOSUN\TSMaster\Data\compilers\llvm_mingw_x86\bin/../include/c++/v1/__support/win32/locale_win32.h:189:19: note: expanded from macro 'strtoll_l' 189 | #define strtoll_l _strtoi64_l | ^ In file included from D:\TS_Master\TSMaster\Configuration\TOSUN\TSMaster\MiniProgram\Build\CCode7142\CCode7142Extern.cpp:7: In file included from C:\Program Files (x86)\TOSUN\TSMaster\Data\compilers\llvm_mingw_x86\bin/../include/c++/v1/vector:325: In file included from C:\Program Files (x86)\TOSUN\TSMaster\Data\compilers\llvm_mingw_x86\bin/../include/c++/v1/__format/formatter_bool.h:20: In file included from C:\Program Files (x86)\TOSUN\TSMaster\Data\compilers\llvm_mingw_x86\bin/../include/c++/v1/__format/formatter_integral.h:35: C:\Program Files (x86)\TOSUN\TSMaster\Data\compilers\llvm_mingw_x86\bin/../include/c++/v1/locale:751:68: error: use of undeclared identifier '_strtoui64_l' 751 | unsigned long long __ll = strtoull_l(__a, &__p2, __base, _LIBCPP_GET_C_LOCALE); | ^ C:\Program Files (x86)\TOSUN\TSMaster\Data\compilers\llvm_mingw_x86\bin/../include/c++/v1/__support/win32/locale_win32.h:190:20: note: expanded from macro 'strtoull_l' 190 | #define strtoull_l _strtoui64_l | ^ In file included from D:\TS_Master\TSMaster\Configuration\TOSUN\TSMaster\MiniProgram\Build\CCode7142\CCode7142Extern.cpp:7: In file included from C:\Program Files (x86)\TOSUN\TSMaster\Data\compilers\llvm_mingw_x86\bin/../include/c++/v1/vector:325: In file included from C:\Program Files (x86)\TOSUN\TSMaster\Data\compilers\llvm_mingw_x86\bin/../include/c++/v1/__format/formatter_bool.h:20: In file included from C:\Program Files (x86)\TOSUN\TSMaster\Data\compilers\llvm_mingw_x86\bin/../include/c++/v1/__format/formatter_integral.h:35: C:\Program Files (x86)\TOSUN\TSMaster\Data\compilers\llvm_mingw_x86\bin/../include/c++/v1/locale:781:10: error: use of undeclared identifier '_strtod_l' 781 | return strtod_l(__a, __p2, _LIBCPP_GET_C_LOCALE); | ^ C:\Program Files (x86)\TOSUN\TSMaster\Data\compilers\llvm_mingw_x86\bin/../include/c++/v1/__support/win32/locale_win32.h:191:18: note: expanded from macro 'strtod_l' 191 | #define strtod_l _strtod_l | ^ In file included from D:\TS_Master\TSMaster\Configuration\TOSUN\TSMaster\MiniProgram\Build\CCode7142\CCode7142Extern.cpp:7: In file included from C:\Program Files (x86)\TOSUN\TSMaster\Data\compilers\llvm_mingw_x86\bin/../include/c++/v1/vector:325: In file included from C:\Program Files (x86)\TOSUN\TSMaster\Data\compilers\llvm_mingw_x86\bin/../include/c++/v1/__format/formatter_bool.h:20: In file included from C:\Program Files (x86)\TOSUN\TSMaster\Data\compilers\llvm_mingw_x86\bin/../include/c++/v1/__format/formatter_integral.h:35: C:\Program Files (x86)\TOSUN\TSMaster\Data\compilers\llvm_mingw_x86\bin/../include/c++/v1/locale:1023:7: error: use of undeclared identifier '_sscanf_l' 1023 | if (__libcpp_sscanf_l(__buf.c_str(), _LIBCPP_GET_C_LOCALE, "%p", &__v) != 1) | ^ C:\Program Files (x86)\TOSUN\TSMaster\Data\compilers\llvm_mingw_x86\bin/../include/c++/v1/__locale_dir/locale_base_api/bsd_locale_defaults.h:34:32: note: expanded from macro '__libcpp_sscanf_l' 34 | #define __libcpp_sscanf_l(...) sscanf_l(__VA_ARGS__) | ^ C:\Program Files (x86)\TOSUN\TSMaster\Data\compilers\llvm_mingw_x86\bin/../include/c++/v1/__support/win32/locale_win32.h:227:38: note: expanded from macro 'sscanf_l' 227 | #define sscanf_l(__s, __l, __f, ...) _sscanf_l(__s, __f, __l, __VA_ARGS__) | ^ In file included from D:\TS_Master\TSMaster\Configuration\TOSUN\TSMaster\MiniProgram\Build\CCode7142\CCode7142Extern.cpp:7: In file included from C:\Program Files (x86)\TOSUN\TSMaster\Data\compilers\llvm_mingw_x86\bin/../include/c++/v1/vector:325: In file included from C:\Program Files (x86)\TOSUN\TSMaster\Data\compilers\llvm_mingw_x86\bin/../include/c++/v1/__format/formatter_bool.h:20: In file included from C:\Program Files (x86)\TOSUN\TSMaster\Data\compilers\llvm_mingw_x86\bin/../include/c++/v1/__format/formatter_integral.h:35: C:\Program Files (x86)\TOSUN\TSMaster\Data\compilers\llvm_mingw_x86\bin/../include/c++/v1/locale:1106:12: error: use of undeclared identifier '_isxdigit_l'; did you mean 'isxdigit'? 1106 | if (!isxdigit_l(*__ns, _LIBCPP_GET_C_LOCALE)) | ^ C:\Program Files (x86)\TOSUN\TSMaster\Data\compilers\llvm_mingw_x86\bin/../include/c++/v1/__support/win32/locale_win32.h:204:20: note: expanded from macro 'isxdigit_l' 204 | #define isxdigit_l _isxdigit_l | ^ C:\Program Files (x86)\TOSUN\TSMaster\Data\compilers\llvm_mingw_x86\bin/../include/c++/v1/cctype:122:9: note: 'isxdigit' declared here 122 | using ::isxdigit _LIBCPP_USING_IF_EXISTS; | ^ In file included from D:\TS_Master\TSMaster\Configuration\TOSUN\TSMaster\MiniProgram\Build\CCode7142\CCode7142Extern.cpp:7: In file included from C:\Program Files (x86)\TOSUN\TSMaster\Data\compilers\llvm_mingw_x86\bin/../include/c++/v1/vector:325: In file included from C:\Program Files (x86)\TOSUN\TSMaster\Data\compilers\llvm_mingw_x86\bin/../include/c++/v1/__format/formatter_bool.h:20: In file included from C:\Program Files (x86)\TOSUN\TSMaster\Data\compilers\llvm_mingw_x86\bin/../include/c++/v1/__format/formatter_integral.h:35: C:\Program Files (x86)\TOSUN\TSMaster\Data\compilers\llvm_mingw_x86\bin/../include/c++/v1/locale:1106:12: error: too many arguments to function call, expected 1, have 2; did you mean '::std::isxdigit'? 1106 | if (!isxdigit_l(*__ns, _LIBCPP_GET_C_LOCALE)) | ^~~~~~~~~~ C:\Program Files (x86)\TOSUN\TSMaster\Data\compilers\llvm_mingw_x86\bin/../include/c++/v1/__support/win32/locale_win32.h:204:20: note: expanded from macro 'isxdigit_l' 204 | #define isxdigit_l _isxdigit_l | ^~~~~~~~~~~ C:\Program Files (x86)\TOSUN\TSMaster\Data\compilers\llvm_mingw_x86\bin/../include/c++/v1/cctype:122:9: note: '::std::isxdigit' declared here 122 | using ::isxdigit _LIBCPP_USING_IF_EXISTS; | ^ In file included from D:\TS_Master\TSMaster\Configuration\TOSUN\TSMaster\MiniProgram\Build\CCode7142\CCode7142Extern.cpp:7: In file included from C:\Program Files (x86)\TOSUN\TSMaster\Data\compilers\llvm_mingw_x86\bin/../include/c++/v1/vector:325: In file included from C:\Program Files (x86)\TOSUN\TSMaster\Data\compilers\llvm_mingw_x86\bin/../include/c++/v1/__format/formatter_bool.h:20: In file included from C:\Program Files (x86)\TOSUN\TSMaster\Data\compilers\llvm_mingw_x86\bin/../include/c++/v1/__format/formatter_integral.h:35: C:\Program Files (x86)\TOSUN\TSMaster\Data\compilers\llvm_mingw_x86\bin/../include/c++/v1/locale:1110:12: error: use of undeclared identifier '_isdigit_l'; did you mean 'isdigit'? 1110 | if (!isdigit_l(*__ns, _LIBCPP_GET_C_LOCALE)) | ^ C:\Program Files (x86)\TOSUN\TSMaster\Data\compilers\llvm_mingw_x86\bin/../include/c++/v1/__support/win32/locale_win32.h:203:19: note: expanded from macro 'isdigit_l' 203 | #define isdigit_l _isdigit_l | ^ C:\Program Files (x86)\TOSUN\TSMaster\Data\compilers\llvm_mingw_x86\bin/../include/c++/v1/cctype:115:9: note: 'isdigit' declared here 115 | using ::isdigit _LIBCPP_USING_IF_EXISTS; | ^ In file included from D:\TS_Master\TSMaster\Configuration\TOSUN\TSMaster\MiniProgram\Build\CCode7142\CCode7142Extern.cpp:7: In file included from C:\Program Files (x86)\TOSUN\TSMaster\Data\compilers\llvm_mingw_x86\bin/../include/c++/v1/vector:325: In file included from C:\Program Files (x86)\TOSUN\TSMaster\Data\compilers\llvm_mingw_x86\bin/../include/c++/v1/__format/formatter_bool.h:20: In file included from C:\Program Files (x86)\TOSUN\TSMaster\Data\compilers\llvm_mingw_x86\bin/../include/c++/v1/__format/formatter_integral.h:35: C:\Program Files (x86)\TOSUN\TSMaster\Data\compilers\llvm_mingw_x86\bin/../include/c++/v1/locale:1110:12: error: too many arguments to function call, expected 1, have 2; did you mean '::std::isdigit'? 1110 | if (!isdigit_l(*__ns, _LIBCPP_GET_C_LOCALE)) | ^~~~~~~~~ C:\Program Files (x86)\TOSUN\TSMaster\Data\compilers\llvm_mingw_x86\bin/../include/c++/v1/__support/win32/locale_win32.h:203:19: note: expanded from macro 'isdigit_l' 203 | #define isdigit_l _isdigit_l | ^~~~~~~~~~ C:\Program Files (x86)\TOSUN\TSMaster\Data\compilers\llvm_mingw_x86\bin/../include/c++/v1/cctype:115:9: note: '::std::isdigit' declared here 115 | using ::isdigit _LIBCPP_USING_IF_EXISTS; | ^ D:\TS_Master\TSMaster\Configuration\TOSUN\TSMaster\MiniProgram\Build\CCode7142\CCode7142Extern.cpp:67:17: error: use of undeclared identifier 'vsnprintf_s' 67 | while ((ret = vsnprintf_s(&buf[0], buf.size(), buf.size(), fmt, ap)) == -1) { | ^ D:\TS_Master\TSMaster\Configuration\TOSUN\TSMaster\MiniProgram\Build\CCode7142\CCode7142Extern.cpp:87:17: error: use of undeclared identifier 'vsnprintf_s' 87 | while ((ret = vsnprintf_s(&buf[0], buf.size(), buf.size(), fmt, ap)) == -1) { | ^ D:\TS_Master\TSMaster\Configuration\TOSUN\TSMaster\MiniProgram\Build\CCode7142\CCode7142Extern.cpp:104:110: error: format specifies type 'unsigned int' but the argument has type 's32' (aka 'long') [-Werror,-Wformat] 104 | sprintf(s, "%s %d %03X Tx d %d [%02X %02X %02X %02X %02X %02X %02X %02X]", ADesc, ACAN->FIdxChn, ACAN->FIdentifier, ACAN->FDLC, ACAN->FData[0], ACAN->FData[1], ACAN->FData[2], ACAN->FData[3], ACAN->FData[4], ACAN->FData[5], ACAN->FData[6], ACAN->FData[7]); | ~~~~ ^~~~~~~~~~~~~~~~~ | %03lX D:\TS_Master\TSMaster\Configuration\TOSUN\TSMaster\MiniProgram\Build\CCode7142\CCode7142Extern.cpp:106:68: error: format specifies type 'unsigned int' but the argument has type 's32' (aka 'long') [-Werror,-Wformat] 106 | sprintf(s, "%s %d %03X Tx r %d", ADesc, ACAN->FIdxChn, ACAN->FIdentifier, ACAN->FDLC); | ~~~~ ^~~~~~~~~~~~~~~~~ | %03lX fatal error: too many errors emitted, stopping now [-ferror-limit=] 20 errors generated.
最新发布
09-26
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值