2019/8/25 C语言回顾(6)

对着背影说爱祢 提交于 2019-11-28 11:33:47
1、strcat :字符串连接函数
#include <string.h>
char *strcat(char *dest, const char *src);
char *strncat(char *dest, const char *src, size_t n);
功能:将两个字符串进行连接
参数:1、存放字符串的空间首地址
           2、需要连接的字符串首地址
返回值:dest
 
注意:strncat会在后面补上‘\0’
 
2、strcmp:字符串比较函数
#include <string.h>
int strcmp(const char *s1, const char *s2);
int strncmp(const char *s1, const char *s2, size_t n);
功能:比较两个字符串n
参数:1、字符串首地址
           2、字符串首地址
返回值:1、如果两个字符串完全一样,返回0,
              2、 如果比较到某一个字符不相同,s1 > s2,返回正数(1),s1<s2,返回负数(-1)
 
strncmp,只比较两个字符串前n个字符字符型指针
char *str = "hello";
 
3、strlen:字符串长度
#include <string.h>
size_t strlen(const char *s);
功能:计算字符串长度(不包含‘\0’)
参数:字符串首地址
返回值:字符串中除‘\0’的字符个数
 
4、strcpy:字符串拷贝
#include <string.h>
char *strcpy(char *dest, const char *src);
功能:将字符串拷贝到指定的空间中
参数:1、存放字符串的地址
        2、需要拷贝的字符串
返回值:dest
注意:src的'\0'也会拷贝,dest的空间需要足够大,不能进行自拷贝
 
char *strncpy(char *dest, const char *src, size_t n);
 
5、void
void *  可以接收任意类型的指针,在使用的时候需要强转成原来的类型。
 
 

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!