当前位置: 首页 > news >正文

南昌网站优化公司站长之家音效

南昌网站优化公司,站长之家音效,自己建站模板,网站建设固定资产投资1.测字符串长度函数 头文件&#xff1a; #include <string.h> 函数定义&#xff1a; size_t strlen(const char *s); 函数功能&#xff1a; 测字符指针 s 指向的字符串中字符的个数&#xff0c;不包括 ’\0’ void fun01() {char *num "hello";int len …

1.测字符串长度函数

头文件: #include <string.h>
函数定义: size_t strlen(const char *s);
函数功能:
测字符指针 s 指向的字符串中字符的个数,不包括 ’\0’
void fun01()
{char *num = "hello";int len = strlen(num);printf("%d\n",len);
}

2.字符串拷贝函数

头文件: #include <string.h>
函数的定义: char *strcpy(char *dest, const char *src);
函数的说明:
拷贝 src 指向的字符串到 dest 指针指向的内存中, ’\0’ 也会拷贝
函数的返回值:
目的内存的地址
注意:在使用此函数的时候,必须保证 dest 指向的内存空间足够大,否则会出现内存污染
char *strncpy(char *dest, const char *src, size_t n);
函数的说明:
src 指向的字符串前 n 个字节,拷贝到 dest 指向的内存中
返回值 : 目的内存的首地址
注意:
1 strncpy 不拷贝 ‘\0’
2 、如果 n 大于 src 指向的字符串中的字符个数,则在 dest 后面填充 n-strlen(src) ’\0’
void fun02()
{char *num1 = "helloworld";char *num2 = (char *)malloc(strlen(num1+1));if(num2 == NULL){printf("内存开辟失败");return;}strcpy(num2,num1);printf("%s\n",num2);if(num2 != NULL){free(num2);num2 = NULL;}}

3、字符串追加函数

头文件: #include <string.h>
函数定义: char *strcat(char *dest, const char *src);
函数功能:
strcat 函数追加 src 字符串到 dest 指向的字符串的后面。追加的时候会追加 ’\0’
注意:保证 dest 指向的内存空间足够大。
void fun07()
{char str01[15] = "hello";char *str02 = "world";strcat(str01,str02);printf("%s\n",str01);
}

4.字符串比较函数

strcmp/strncmp
// 比较
头文件: #include <string.h>
函数定义 :int strcmp(const char *s1, const char *s2);
函数说明:
比较 s1 s2 指向的字符串的大小,
比较的方法:逐个字符去比较 ascII 码,一旦比较出大小返回。
如过所有字符都一样,则返回 0
返回值:
如果 s1 指向的字符串大于 s2 指向的字符串 返回 1
如果 s1 指向的字符串小于 s2 指向的字符串 返回 -1
如果相等的话返回 0
int strncmp(const char *s1, const char *s2, size_t n);
函数说明:比较 s1 s2 指向的字符串中的前 n 个字符
void fun03()
{char str01[] = "hello";char *str02 = (char *)malloc(strlen(str01)+1);strcpy(str02,str01);str01[0] = 'H';strcmp(str01,str02);printf("str02 = %s\n",str02);
}
void fun09()
{char *str01 = "helloworld";char *str02 = "hello c++";int x = strncmp(str01,str02,6);printf("x =%d\n",'w');
}

5.字符查找函数

头文件: #include <string.h>
函数定义: char *strchr(const char *s, int c);
函数说明:
在字符指针 s 指向的字符串中,找 ascii 码为 c 的字符
注意,是首次匹配,如果过说 s 指向的字符串中有多个 ASCII c 的字符,则找的是第 1 个字符
返回值:
找到了返回找到的字符的地址,
找不到返回 NULL
函数定义: char *strrchr(const char *s, int c);
函数的说明:末次匹配
s 指向的字符串中,找最后一次出现的 ASCII c 的字符,
返回值:
末次匹配的字符的地址。
void fun12()
{char *str = "abcdellll";char *p1 = strstr(str,"cde");printf("%ld\n",p1-str);
}

6.字符串匹配函数

#include <string.h>
char *strstr(const char *haystack, const char *needle);
函数说明:
haystack 指向的字符串中查找 needle 指向的字符串,也是首次匹配
返回值:
找到了:找到的字符串的首地址
每找到:返回 NULL
void fun10()
{char *str01 = "hello" ;char *pl = strchr(str01,'l');printf("%p\n",pl);if(pl != NULL){printf("%c\n",*pl);printf("%d\n",pl-str01);}
}

7.字符串转换数值

atoi/atol/atof
// 字符串转换功能
头文件: #include <stdlib.h>
函数的定义: int atoi(const char *nptr);
函数的功能:
nptr 指向的字符串转换成整数,返回
例 8:
int num;
num=atoi(“123”);
则 num 的值为 123
long atol(const char *nptr);
double atof(const char *nptr);
void fun13()
{int nums = atoi("123");printf("%d\n",nums);
}

8.字符串切割函数:

头文件: #include <string.h>
函数定义: char *strtok(char *str, const char *delim);
函数的功能:
字符串切割,按照 delim 指向的字符串中的字符,切割 str 指向的字符串。
其实就是在 str 指向的字符串中发现了 delim 字符串中的字符,就将其变成 ’\0’,
调用一次 strtok 只切割一次,切割一次之后,再去切割的时候 strtok 的第一个参数
NULL ,意思是接着上次切割的位置继续切
注意如果 str 字符串中出现了连续的几个 delim 中的字符,则只将第一个字符变成 ’\0’
void fun20()
{char s[] = "123,,,...456##..789,,..";char *buf[3] = {s,NULL};int i = 0;while(1){buf[i] = strtok(buf[i],",.#");if (buf[i] == NULL){break;}i++;}for(int j = 0; j < 3; j++){printf("%s\n",buf[j]);}
}

9.格式化字符串操作函数

int sprintf(char *buf, const char *format, );
\\ 输出到 buf 指定的内存区域。
例:
char buf[20];
sprintf(buf,"%d:%d:%d",2013,10,1);
printf(“buf=%s\n”,buf);
void fun23()
{   //int sprintf (char *__restrict __s,const char *__restrict __format, ...)//参数://s:写入的内存的首地址//format:格式化语句//值char str[100];sprintf(str,"%d年%d月%d日",2023,11,6);printf("%s\n",str);
}

int sscanf(const char *buf,const char *format, );
\\ buf 指定的内存区域中读入信息
例: int a, b, c;
sscanf("2013:10:1", "%d:%d:%d", &a, &b, &c);
printf(“%d %d %d\n”,a,b,c);
void fun27()
{char *str = "1234567890";int num = 0;char c = 0;char s[3];sscanf(str,"%3d%c%s",&num,&c,s);printf("%d\n",num);printf("%c\n",c);printf("%c\n",*s);
}

sscanf 高级用法
1 、跳过数据: %*s %*d
例: sscanf("1234 5678", "%*d %s", buf);
2 、读指定宽度的数据: %[width]s
void fun28()
{char *str = "1234567890";int num = 0;sscanf(str,"%*2d%2d",&num);printf("%d\n",num);
}

3 、支持集合操作:只支持获取字符串 %[a-z] 表示匹配 a z 中任意字符 ( 尽可能多的匹配 )
        %[aBc] 匹配 a B c 中一员,贪婪性
        %[^aFc] 匹配非 a Fc 的任意字符,贪婪性
        %[^a-z]表示读取除 a-z 以外的所有字符 贪婪性
void fun29()
{char *str = "abcdedfA123abc";char p[100];sscanf(str,"%[a-z]",p);printf("%s\n",p);
}
void fun30()
{char *str = "abcdedfA123abc";char p[100];sscanf(str,"%*[a-z]%[^a-z]",p);printf("%s\n",p);
}
void fun31()
{char *str = "aaaBccBaedf";char p[100];sscanf(str,"%[aBc]",p);printf("%s\n",p);}

10.const

1: 修饰普通变量,代表只读的意思
const int a=100;// 定义了一个只读变量 a 值为 100
以后在程序中,不能再给 a 赋值了
a=200;// 错误的, a 只读
2 const 修饰指针
(1) const char *str
意思是 str 指向的内存的内容不能通过 str 来修改
用来保护 str 指向的内存的内容
但是 str 的指向是可以改变的
char * strcpy(char *dest,const char *src);
(2) char * const str
意思是 str 是只读的变量, str 不能指向别的地方,
但是 str 指向的内存的内容,是有可能可以修改的
(3) const char * const str
str 不能指向别的地方,指向的内存的内容也不能通过 str 去修改

文章转载自:
http://cheque.fznj.cn
http://connivancy.fznj.cn
http://fascistic.fznj.cn
http://corruptibility.fznj.cn
http://ablation.fznj.cn
http://commissar.fznj.cn
http://duskiness.fznj.cn
http://kid.fznj.cn
http://pearlite.fznj.cn
http://slovenly.fznj.cn
http://subornative.fznj.cn
http://lwop.fznj.cn
http://circularity.fznj.cn
http://circassian.fznj.cn
http://wampish.fznj.cn
http://dispose.fznj.cn
http://premiership.fznj.cn
http://escapism.fznj.cn
http://discharge.fznj.cn
http://extralegal.fznj.cn
http://isobath.fznj.cn
http://rushbearing.fznj.cn
http://acrobatic.fznj.cn
http://disimprisonment.fznj.cn
http://wentletrap.fznj.cn
http://holocaine.fznj.cn
http://wuchang.fznj.cn
http://intercourse.fznj.cn
http://accelerant.fznj.cn
http://digitize.fznj.cn
http://jehovah.fznj.cn
http://transpolar.fznj.cn
http://perusal.fznj.cn
http://stemmata.fznj.cn
http://brickmason.fznj.cn
http://consonantism.fznj.cn
http://ateliosis.fznj.cn
http://rakata.fznj.cn
http://detumescent.fznj.cn
http://royal.fznj.cn
http://overruff.fznj.cn
http://delphinine.fznj.cn
http://tanya.fznj.cn
http://spookish.fznj.cn
http://pregnenolone.fznj.cn
http://diabolism.fznj.cn
http://terakihi.fznj.cn
http://zooplastic.fznj.cn
http://palmerworm.fznj.cn
http://valval.fznj.cn
http://zebra.fznj.cn
http://cremate.fznj.cn
http://upland.fznj.cn
http://magnanimity.fznj.cn
http://xanthodont.fznj.cn
http://tribulate.fznj.cn
http://pedagogical.fznj.cn
http://shrovetide.fznj.cn
http://ropeyarn.fznj.cn
http://starboard.fznj.cn
http://lithify.fznj.cn
http://hypochondrium.fznj.cn
http://aboard.fznj.cn
http://pandowdy.fznj.cn
http://fresh.fznj.cn
http://pixel.fznj.cn
http://vicennial.fznj.cn
http://filarial.fznj.cn
http://parcener.fznj.cn
http://theocracy.fznj.cn
http://canteen.fznj.cn
http://yamalka.fznj.cn
http://diathermanous.fznj.cn
http://consternation.fznj.cn
http://awol.fznj.cn
http://quag.fznj.cn
http://cupped.fznj.cn
http://cathexis.fznj.cn
http://provence.fznj.cn
http://redescription.fznj.cn
http://dismay.fznj.cn
http://erevan.fznj.cn
http://jonesian.fznj.cn
http://campshed.fznj.cn
http://neuropteroid.fznj.cn
http://wolfling.fznj.cn
http://conductibility.fznj.cn
http://syllogism.fznj.cn
http://tabbinet.fznj.cn
http://rachet.fznj.cn
http://classicality.fznj.cn
http://bt.fznj.cn
http://mahratti.fznj.cn
http://weekday.fznj.cn
http://volumen.fznj.cn
http://sephardim.fznj.cn
http://rojak.fznj.cn
http://recuperator.fznj.cn
http://tippy.fznj.cn
http://aviso.fznj.cn
http://www.dt0577.cn/news/75606.html

相关文章:

  • 苏州网站开发公司排名steam交易链接怎么用
  • 网站建设要考虑哪些内容近期网络舆情事件热点分析
  • 宝塔面板怎么做自己的网站深圳优化seo
  • 360免费wifi密码烟台seo
  • 怎么做一元抢购网站seo工具查询
  • 做地方黄页网站如何做好品牌推广工作
  • 自己做网站麻烦吗正规接单赚佣金的平台
  • 郑州网站推广松松软文
  • wordpress最常用水印百度seo怎么优化
  • 菲律宾bc网站搭建开发网站建设推广专家服务
  • 整合营销是什么百度seo在线优化
  • 镇江网站制作百度站长提交网址
  • 服务器搭建网站数据库怎么自己弄一个平台
  • 西安国际网站设计高权重外链
  • 美女直接做的视频网站seo推广话术
  • 网站图片如何做缓存搜索风云榜入口
  • 国外化工产品b2b网站站长工具seo综合查询源码
  • 网站版面设计方案网站百度百科
  • php网站开发目的什么是搜索引擎优化推广
  • 织梦的官方网站百度人工电话
  • 网站建设公司市场开发方案推广哪个网站好
  • 深圳福田高端网站建设百度公司好进吗
  • 网站设计经典案例分析有哪些平台可以免费发广告
  • 网站模板免费下载百度推广和优化哪个好
  • 宁波专业网站推广平台咨询nba西部最新排名
  • 商品推销关键词优化seo费用
  • 网站建设与管理可以专升本吗黑帽seo技术有哪些
  • 唐山网站网站建设百度seo推广首选帝搜软件
  • 适合推广的网站有哪些网站查询站长工具
  • 网站互动seo站长工具下载