c语言_字符串函数
字符串拷贝函数
字符串拼接函数
字符串比较函数
格式化处理字符串
字符串转为数字函数
字符串拷贝函数
字符串查找函数
strcpy
strcpy 字符串函数拷贝,一般用来将字符串拷贝到定义的字符数组中。
strncpy 字符串拷贝函数,用来拷贝字符串的一部分到定义的字符数组中。
字符串拼接函数
strcat
strcat 字符串连接函数,一般用来在字符串后拼接字符串。
#include <string.h> char *strcat(char *dest, const char *src); char *strncat(char *dest, const char *src, size_t n);
字符串比较函数
strcmp
strcmp(const char* s1, const char* s2)
返回值:
s1和s2相等,返回0。
s1比s2大,返回正数。
s1比s2小,返回负数。
格式化处理字符串
sprintf、sscanf
sprintf可以将多种不同的数据类型放入到字符数组中。
#include <stdio.h>
int sprintf(char *str, const char *format, ...);
int snprintf(char *str, size_t size, const char *format, ...);
int sscanf(const char *str, const char *format, ...);
#include <stdio.h> #include <stdlib.h> int main(){ char buf[1024] = {0}; int year=2020, month=12, day=23; sprintf(buf, "%d-%d-%d", year, month, day); puts(buf); exit(0); }
![]()
字符串转为数字函数
atoi 该函数主要是将一个字符串转换为一个整型数。
#include <stdlib.h> int atoi(const char *nptr);
atoi,如果遇到字符那么就停止转换。
#include <stdio.h> #include <stdlib.h> int main(void){ char str[] = "123456"; char str2[] = "123a456"; printf("%d\n", atoi(str)); printf("%d\n", atoi(str2)); return 0; }

字符串查找函数
strstr
strstr主要是在一个字符串中找到另一个字符串。
strstr("ta_netvalue_confirm", "ta_netvalue")
posted on 2020-12-23 22:05 XiaoXiaoli 阅读(93) 评论(0) 收藏 举报
浙公网安备 33010602011771号