c语言字符串相关函数
Binary Oracle
一名热爱开源和技术的Coder , 开源框架spring committer , golang开源网络库netpoll committer; (脱产备战25考研中,停更一年)
展开
-
atoi字符串转数字
包含头文件:stdlib.h函数原型用法:将字符串里的数字字符转化为整形数。返回整形值。注意:转化时跳过前面的空格字符,直到遇上数字或正负符号才开始做转换,而再遇到非数字或字符串结束时(’/0’)才结束转换,并将结果返回。#define _CRT_SECURE_NO_WARNINGS#include<stdio.h>#include<string.h>#include<stdlib.h>//atoi字符串转数字void test(){ cha原创 2021-02-16 12:05:26 · 564 阅读 · 0 评论 -
strtok字符串分割函数
函数原型:原创 2021-02-16 11:43:44 · 354 阅读 · 0 评论 -
字符数组和字符串指针变量区别
字符串指针变量:无法修改所指向字符串内容字符数组:将常量区的字符串拷贝一份到栈区,可以对栈区字符串内容进行修改原创 2021-02-13 09:56:42 · 177 阅读 · 0 评论 -
字符数组输入输出---fputs,gets_s,puts,fputs
要点1字符数组初始化:1.逐个字符初始化,如果不在结尾加\0,用%s输出会乱码#define _CRT_SECURE_NO_WARNINGS#include<stdio.h>#include<string.h>void test(){ //初始化方式1 char arr[5] = { 'a','b','c','d','c' }; printf("%s\n", arr);}int main(){ test(); return 0;}正确写法:原创 2021-02-13 09:56:18 · 555 阅读 · 0 评论 -
c语言比较函数
strcmp()函数:原创 2021-02-13 09:56:07 · 5311 阅读 · 0 评论 -
sscanf函数-----字符串拆分函数
sscanf函数sscanf的作用:从一个字符串中读进于指定格式相符的数据。利用它可以从字符串中取出整数、浮点数和字符串。sscanf和scanf的区别:scanf是以键盘作为输入源,sscanf是以字符串作为输入源。提取某个字符串中的有效信息,放入指定变量或字符串中跟scanf一样,遇到空格结束读取#define _CRT_SECURE_NO_WARNINGS#include<stdio.h>#include<string.h>void test(){原创 2021-02-13 09:55:52 · 4784 阅读 · 0 评论 -
sprintf函数---c语言字符串格式化
sprintf函数#define _CRT_SECURE_NO_WARNINGS#include<stdio.h>#include<string.h>void test(){ //sprintf函数 //格式化字符串 int year=2021, month=2, day=12; char str[64] = { 0 }; sprintf(str, "今天是%d年%d几月%d几日", year, month, day); printf("%s", s原创 2021-02-13 09:55:33 · 429 阅读 · 0 评论 -
strchr函数-----c语言字符串查找函数
strchr函数返回第一次出现字符c的地址,要用指针去接收#define _CRT_SECURE_NO_WARNINGS#include<stdio.h>#include<string.h>int main(){ char str[100] = "123456789@qq.com"; char* pos = strchr(str, '@'); if (pos == NULL) { printf("没有查找到@符号"); } else { prin原创 2021-02-13 09:55:14 · 329 阅读 · 0 评论 -
strstr函数---字符串查找函数
#define _CRT_SECURE_NO_WARNINGS#include<stdio.h>#include<string.h>//strstr字符串查找函数void findStr(){ char str[64]; //遇到空格不会停止,遇到换行符会停止输入 //但会带走缓冲区的换行符 fgets(str, sizeof(str), stdin); //将结尾的\n换成\0 str[strlen(str)-1]='\0'; //字符串比较 //找到.原创 2021-02-13 09:54:51 · 1022 阅读 · 0 评论 -
c语言字符串之拼接函数
strcat函数:#define _CRT_SECURE_NO_WARNINGS#include<stdio.h>//关于字符串的操作要包含头文件sting.h#include<string.h>int main(){ //strcat char c1[32] = { 0 }; char c2[32] = { 0 }; strcat(c1, "hello"); printf("%s", c1); strcat(c2, " world"); printf("原创 2021-02-11 13:03:29 · 8192 阅读 · 0 评论 -
c语言字符串之拷贝函数
1.strcpy函数2.strncpy函数**代码演示: **strcpy函数:#define _CRT_SECURE_NO_WARNINGS#include<stdio.h>//关于字符串的操作要包含头文件sting.h#include<string.h>int main(){ //1. //strcpy字符串拷贝函数 char str1[] = "大忽悠"; char str2[] = "你好,世界"; strcpy(str2, str1); //原创 2021-02-11 12:48:06 · 1761 阅读 · 1 评论