C语言和C++下字符串处理函数概括
发布时间:2021-11-22 11:28:29 所属栏目:PHP教程 来源:互联网
导读:一、ctype.h字符处理库中的函数 #includectype.h 函数原型:int f(int c) 函数说明:C语言定义的处理字符操作,包括是否是数字,字母,打印字符,十六进制数字,大小写转换等, 具体如下: isalnum:Check if character is alphanumeric (function) isalpha
一、<ctype.h>字符处理库中的函数 #include<ctype.h> 函数原型:int f(int c) 函数说明:C语言定义的处理字符操作,包括是否是数字,字母,打印字符,十六进制数字,大小写转换等, 具体如下: isalnum:Check if character is alphanumeric (function) isalpha :Check if character is alphabetic (function) iscntrl :Check if character is a control character (function) isdigit :Check if character is decimal digit (function) isgraph :Check if character has graphical representation (function ) islower :Check if character is lowercase letter (function) isprint :Check if character is printable (function) ispunct :Check if character is a punctuation character (function) isspace :Check if character is a white-space (function )--空白字符:新行符n, 空格,回车''r",水平制表符"t", 垂直制表符"v" isupper :Check if character is uppercase letter (function) isxdigit :Check if character is hexadecimal digit (function) tolower:Convert uppercase letter to lowercase (function) toupper:Convert lowercase letter to uppercase (function) 二、<stdio.h >字符串和字符输入/输出的函数 #include <stdio.h> int getchar(void) ;//从标准输入设备读取字符以整数返回 char * get(char * s) ;//从标准输入设备读入字符到数组s直到遇到新行符和文件结束符为止,然后再数组后追加NULL字符 int putchar(int c) ;// 打印字符 int puts(const char * s);// 打印字符串s和新行符 int sprintf(char * s, const char * format) ;//与printf区别在于输出结果存放在s中 (常用于规定格式转换或者输出) int sscanf(char * s, const char * format); ;//与scanf区别在于从数组s读取数据(常用于规定格式转换或者输入) 三、<stdlib.h>中的字符串转换函数 #include<stdlib.h> 1. atoi(将字符串转换成整型数) 定义函数:int atoi(const char *nptr) 函数说明:atoi()会扫描参数nptr字符串,跳过前面的空格字符,直到遇上数字或正负符号才开始做转换,而再遇到非数字或字符串结束时(' |