c语言字符串库函数#include<string.h>
字符串函数<string.h>
在头文件<string.h>中定义了两组字符串函数。第一组函数的名字以str开头;第二组函数的名字以mem开头。只有函数memmove对重叠对象间的拷贝进行了定义,而其他函数都未定义。比较类函数将其变量视为unsigned char类型的数组。
1 strcpy
#include <string.h>
char *strcpy(char *str1, const char *str2);
把字符串str2(包括'\0')拷贝到字符串str1当中,并返回str1。
2 strncpy
#include <string.h>
char *strncpy(char *str1, const char *str2, size_t count);
把字符串str2中最多count个字符拷贝到字符串str1中,并返回str1。如果str2中少于count个字符,那么就用'\0'来填充,直到满足count个字符为止。
3 strcat
#include <string.h>
char *strcat(char *str1, const char *str2);
把str2(包括'\0')拷贝到str1的尾部(连接),并返回str1。其中终止原str1的'\0'被str2的第一个字符覆盖。
4 strncat
#include <string.h>
char *strncat(char *str1, const char *str2, size_t count);
把str2中最多count个字符连接到str1的尾部,并以'\0'终止str1,返回str1。其中终止原str1的'\0'被str2的第一个字符覆盖。
注意,最大拷贝字符数是count+1。
5 strcmp
#include <string.h>
int strcmp(const char *str1, const char *str2);
按字典顺序比较两个字符串,返回整数值的意义如下:
- 小于0,str1小于str2;
- 等于0,str1等于str2;
- 大于0,str1大于str2;
6 strncmp
#include <string.h>
int strncmp(const char *str1, const char *str2, size_t count);
同strcmp,除了最多比较count个字符。根据比较结果返回的整数值如下:
- 小于0,str1小于str2;
- 等于0,str1等于str2;
- 大于0,str1大于str2;
7 strchr
#include <string.h>
char *strchr(const char *str, int ch);
返回指向字符串str中字符ch第一次出现的位置的指针,如果str中不包含ch,则返回NULL。
8 strrchr
#include <string.h>
char *strrchr(const char *str, int ch);
返回指向字符串str中字符ch最后一次出现的位置的指针,如果str中不包含ch,则返回NULL。
9 strspn
#include <string.h>
size_t strspn(const char *str1, const char *str2);
返回字符串str1中由字符串str2中字符构成的第一个子串的长度。
10 strcspn
#include <string.h>
size_t strcspn(const char *str1, const char *str2);
返回字符串str1中由不在字符串str2中字符构成的第一个子串的长度。
11 strpbrk
#include <string.h>
char *strpbrk(const char *str1, const char *str2);
返回指向字符串str2中的任意字符第一次出现在字符串str1中的位置的指针;如果str1中没有与str2相同的字符,那么返回NULL。
12 strstr
#include <string.h>
char *strstr(const char *str1, const char *str2);
返回指向字符串str2第一次出现在字符串str1中的位置的指针;如果str1中不包含str2,则返回NULL。
13 strlen
#include <string.h>
size_t strlen(const char *str);
返回字符串str的长度,'\0'不算在内。
14 strerror
#include <string.h>
char *strerror(int errnum);
返回指向与错误序号errnum对应的错误信息字符串的指针(错误信息的具体内容依赖于实现)。
15 strtok
#include <string.h>
char *strtok(char *str1, const char *str2);
在str1中搜索由str2中的分界符界定的单词。
对strtok()的一系列调用将把字符串str1分成许多单词,这些单词以str2中的字符为分界符。第一次调用时str1非空,它搜索str1,找出由非str2中的字符组成的第一个单词,将str1中的下一个字符替换为'\0',并返回指向单词的指针。随后的每次strtok()调用(参数str1用NULL代替),均从前一次结束的位置之后开始,返回下一个由非str2中的字符组成的单词。当str1中没有这样的单词时返回NULL。每次调用时字符串str2可以不同。
如:
char *p;
p = strtok("The summer soldier,the sunshine patriot", " ");
printf("%s", p);
do {
p = strtok("\0", ", "); /* 此处str2是逗号和空格 */
if (p)
printf("|%s", p);
} while (p);
显示结果是:The | summer | soldier | the | sunshine | patriot
16 memcpy
#include <string.h>
void *memcpy(void *to, const void *from, size_t count);
把from中的count个字符拷贝到to中。并返回to。
17 memmove
#include <string.h>
void *memmove(void *to, const void *from, size_t count);
功能与memcpy类似,不同之处在于,当发生对象重叠时,函数仍能正确执行。
18 memcmp
#include <string.h>
int memcmp(const void *buf1, const void *buf2, size_t count);
比较buf1和buf2的前count个字符,返回值与strcmp的返回值相同。
19 memchr
#include <string.h>
void *memchr(const void *buffer, int ch, size_t count);
返回指向ch在buffer中第一次出现的位置指针,如果在buffer的前count个字符当中找不到匹配,则返回NULL。
20 memset
#include <string.h>
void *memset(void *buf, int ch, size_t count);
把buf中的前count个字符替换为ch,并返回buf。
c语言字符串库函数#include<string.h>的更多相关文章
- c语言实用功能库函数#include<stdlib.h>
实用函数<stdlib.h> 在头文件<stdlib.h>中说明了用于数值转换.内存分配以及具有其他相似任务的函数. 1 atof #include <stdlib.h& ...
- c语言时间库函数#include<time.h>
日期与时间函数<time.h> 头文件<time.h>中说明了一些用于处理日期和时间的类型和函数.其中的一部分函数用于处理当地时间,因为时区等原因,当地时间与日历时间可能不相同 ...
- #include <string.h>
1 _memccpy 2 _memicmp 3 _strlwr 4 _strrev 5 _strset 6 _strupr 7 memccpy 8 memchr 9 memcpy 10 memicmp ...
- 字符串操作函数<string.h>相关函数strcpy,strcat,等源码。
首先说一下源码到底在哪里找. 我们在文件中包含<cstring>时,如果点击右键打开文档, 会打开cstring,我们会发现路径为: D:\Program Files\visual stu ...
- 5. 常见C语言字符串库函数的使用及实现
1. strncat 函数: [函数原型]#include <string.h> char *strncat( char *str1, const char *str2, size_t c ...
- #include<string.h>
#include<string.h> 1 strcpy #include <string.h> char *strcpy(char *str1, const char *str ...
- #include<iostream>与#include<iostream.h>以及#inclue<string> 和 #include<string.h>的区别
转载于:http://www.cnblogs.com/charley_yang/archive/2010/12/08/1900715.html 1.从功能性的角度来讲,<iostream> ...
- [C++]在什么时候需要“#include string.h“
相关资料:https://zhidao.baidu.com/question/515578726.html C++中,string头文件基本上已经包含在iostream中了.但是,平时使用的时候建议加 ...
- c语言输入与输出库函数#include<stdio.h>
last modified: 2010-05-28 输入与输出<stdio.h> 头文件<stdio.h>定义了用于输入和输出的函数.类型和宏.最重要的类型是用于声明文件指针的 ...
随机推荐
- [DLL] Dynamic link library (dll) 的编写和使用教程
前一阵子,项目里需要导出一个DLL,但是导出之后输出一直不怎么对,改了半天才算改对...读了一些DLL教程,感觉之后要把现在的代码导出,应该还要花不少功夫...下面教程参照我读的3个教程写成,所以内容 ...
- Asp.net自带导出方法
///datatable数据源 filename绝对路径 如:E:\\***.xls DataTable.WriteXml(fileName)
- Spring 官方下载地址(非Maven)
现在spring的官网停止了使用zip包下载,只能使用maven,非常的不方便,分享如下网址可以使用zip包下载,是不是方便多了!~ 下载列表如下: spring-framework-3.2.8.RE ...
- rar压缩文件下载
//string fileName = "ceshi.rar";//客户端保存的文件名 //string filePath = Server.MapPath(&qu ...
- Sql Server 判断表或数据库是否存在
发布:thebaby 来源:脚本学堂 [大 中 小] 本文详细介绍了,在sql server中判断数据库或表是否存在的方法,有理论有实例,有需要的朋友可以参考下,一定有帮助的.原文地址:h ...
- IOS中利用宏将RGB值转换为UIColor(转)
可以在pch文件中定义宏,这样整个项目就都可以用了! #define UIColorFromRGBValue(rgbValue) [UIColor colorWithRed:((float)((rgb ...
- poj 1733 Parity game
Parity game 题意:一个长度为N(N < 1e9)内的01串,之后有K(K <= 5000)组叙述,表示区间[l,r]之间1的个数为odd还是even:问在第一个叙述矛盾前说了几 ...
- CODEVS 1069关押罪犯
题目描述 Description S 城现有两座监狱,一共关押着N 名罪犯,编号分别为1~N.他们之间的关系自然也极 不和谐.很多罪犯之间甚至积怨已久,如果客观条件具备则随时可能爆发冲突.我们用“怨 ...
- Catch Application Exceptions in a Windows Forms Application
You need to handle the System.Windows.Forms.Application.ThreadException event for Windows Forms. Thi ...
- Python的字符串操作和Unicode
字符串类型 str:Unicode字符串.采用''或者r''构造的字符串均为str,单引号可以用双引号或者三引号来代替.无论用哪种方式进行制定,在Python内部存储时没有区别. bytes:二进制字 ...