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

app banner设计网站社会新闻热点事件

app banner设计网站,社会新闻热点事件,东莞建外贸网站好,做网站的人会不会拿走我的网站1.复制函数--------------strcpy函数 函数使用 char*strcpy(char* destination, const char* source) strcpy函数用于拷贝字符串,即将一个字符串中的内容拷贝到另一个字符串中(会覆盖原字符串内容)。它的参数是两个指…

1.复制函数--------------strcpy函数

函数使用

char*strcpy(char* destination, const char* source)

  • strcpy函数用于拷贝字符串,即将一个字符串中的内容拷贝到另一个字符串中(会覆盖原字符串内容)。它的参数是两个指针
  • 第一个指针指向目标字符串的首地址,即要拷贝到什么地方。
  • 第二个指针指向来源字符串的首地址,即用什么字符串拷贝。返回值是目标字符串的首地址
    #include<stdio.h>
    #include<string.h>
    int main()
    {//char* p = NULL;//p = "zhangsan";//p是指针变量,可以赋值,将z的地址赋值给p//char name[20] = "xxxxxxxxxx";//name = "zhangsan";//err,name数组名是地址,地址是一个常量值,不能被赋值,name已经被固定死了char name1[20] = "xxxxxxxxxx";char str1[] = "zhang\0san";strcpy(name1, str1);printf("%s\n", name1);char name2[20] = "xxxxxxxxxx";char str2[] = { 'b','i','t' };strcpy(name2, str2);printf("%s\n", name2);//char* p = "abcdef";//p指向常量字符串,存放a的地址,常量字符串是不能修改的//char arr[] = "bit";//strcpy(p, arr);//err//char p[] = "abcdef";//将其放入数组中,使其变成变量可以修改//char arr[] = "bit";//strcpy(p, arr);//rightreturn 0;
    }
    

    模拟实现





    • 复制到时候,函数会将被拷贝字符串的‘/0’一同复制到目标字符串,当字符串没有‘/0‘时,会一直向后查找,直到找到

总结:

  • 源字符串必须以 ‘\0’ 结束。
  • 会将源字符串中的 ‘\0’ 拷贝到目标空间。
  • 目标空间必须足够大,以确保能存放源字符串。
  • 目标空间必须可修改。

.模拟实现

  • 进入函数体时先定义一个指针变量保存目标空间的起始位置,便于之后返回。然后将源字符串中的字符一一赋值给目标空间,直到遇到源字符串中的’\0’,将’\0’也赋值给目标空间后结束赋值,并返回目标空间的起始位置。
#include<assert.h>
char* my_strcpy(char* destination, const char* source)
{assert(str != NULL);//断言,若str为NULL,报错,头文件assert.h//或者直接assert(destination && source);char* str = destination;//保存目标空间的起始位置while (*source != '\0')//或者直接while (*source){*destination++ = *source++;}*destination = *source;return str;
}

二.strcat(字符串追加)

char *strcat( char* destination, const char* Source ); 

strcat函数用于追加字符串,即将一个字符串中的内容追加到另一个字符串中。它的参数是两个指针,

  • 第一个指针指向目标字符串的首地址,即要追加到什么地方。
  • 第二个指针指向来源字符串的首地址,即用什么字符串追加。
  • 返回值是目标字符串的首地址
#include<stdio.h>
#include<string.h>
int main()
{char arr1[20] = "hello ";char arr2[] = "world";strcat(arr1, "world");printf("%s\n", arr2);char arr3[20] = "hello ";char arr4[] = { 'a','b','c','d','e','f' };strcat(arr3, arr4);printf("%s\n", arr3);return 0;
}

三.strcmp(字符串比较)

1.函数使用

int strcmp(const char* str1,const char* str2)

strcmp函数用于比较两个字符串内容的函数。

它的参数是两个指针

指针分别指向两个待比较字符串的首地址。它的返回值是一个整型数字。
依次比较的是对应字符的ASCII值。

  • 当str1 > str2的时候返回正数。
  • 当str1 == str2的时候返回0。
  • 当str1 < str2的时候返回负数。

//错误的写法
#include<stdio.h>
int main()
{char arr1[] = "zhangsan";char arr2[] = "zhangsan";if (arr1 == arr2)printf("==\n");elseprintf("!=\n");//输出!=return 0;
}

//正确的比较方法
#include<stdio.h>
#include<string.h>
int main()
{char arr1[] = "zhangsan";char arr2[] = "zhangsan";int ret = strcmp(arr1, arr2);if (ret < 0)printf("<\n");else if (ret == 0)printf("==\n");//输出==elseprintf(">\n");return 0;
}

  • 第⼀个字符串大于第⼆个字符串,则返回大于0的数字。
  • 第⼀个字符串等于第⼆个字符串,则返回0。
  • 第⼀个字符串小于第⼆个字符串,则返回⼩于0的数字。

那么如何判断两个字符串? 比较两个字符串中对应位置上字符ASCII码值的大小。


2.模拟实现

进入函数体直接比较起始位置的字符的大小。如果相同并且不为’\0’那么继续比较下一对字符的大小;如果相同并且为’\0’那么说明字符串比较完毕,那么直接返回0;如果不同则直接返回str1与str2中对应字符的ASCII值的差值(当str1中对应字符大于str2中的对应字符时返回正值,当str1中对应字符小于str2中的对应字符时返回负值)。

#include<assert.h>
int my_strcmp(const char* str1, const char* str2)
{assert(str1 && str2);//断言,若str为NULL,报错,头文件assert.hwhile (*str1 == *str2){//遇到都为'\0'的时候,说明字符串相等返回0if (*str1 == '\0')return 0;str1++;str2++;}return (*str1 - *str2);
}


文章转载自:
http://dinncoascetical.stkw.cn
http://dinncoeverglade.stkw.cn
http://dinncobrilliancy.stkw.cn
http://dinncocardiotachometer.stkw.cn
http://dinncoplaustral.stkw.cn
http://dinncorespecter.stkw.cn
http://dinncothermidor.stkw.cn
http://dinncodisassemble.stkw.cn
http://dinncoinsociable.stkw.cn
http://dinncobagnio.stkw.cn
http://dinncogrit.stkw.cn
http://dinncooakling.stkw.cn
http://dinncofencer.stkw.cn
http://dinncoarietis.stkw.cn
http://dinncolocale.stkw.cn
http://dinncodroit.stkw.cn
http://dinncoregius.stkw.cn
http://dinncorockfest.stkw.cn
http://dinncofuggy.stkw.cn
http://dinncoslideway.stkw.cn
http://dinncoringsider.stkw.cn
http://dinncobushfighter.stkw.cn
http://dinncobottom.stkw.cn
http://dinncoallonym.stkw.cn
http://dinncohydroa.stkw.cn
http://dinncohaloid.stkw.cn
http://dinncoenate.stkw.cn
http://dinncofireman.stkw.cn
http://dinncokalif.stkw.cn
http://dinncohypochondriasis.stkw.cn
http://dinncotextual.stkw.cn
http://dinncocastaway.stkw.cn
http://dinncoungroup.stkw.cn
http://dinncodisentrance.stkw.cn
http://dinncomop.stkw.cn
http://dinncoobadiah.stkw.cn
http://dinncounwashed.stkw.cn
http://dinncoplacement.stkw.cn
http://dinncospined.stkw.cn
http://dinncoungrateful.stkw.cn
http://dinncocomp.stkw.cn
http://dinncoragamuffin.stkw.cn
http://dinncodunite.stkw.cn
http://dinncoaccoutre.stkw.cn
http://dinncosinfully.stkw.cn
http://dinncoashore.stkw.cn
http://dinncoleprechaun.stkw.cn
http://dinncosupraglottal.stkw.cn
http://dinncobedlam.stkw.cn
http://dinncojetton.stkw.cn
http://dinncobyssinosis.stkw.cn
http://dinncoghaut.stkw.cn
http://dinncotakeoff.stkw.cn
http://dinncolemures.stkw.cn
http://dinncothis.stkw.cn
http://dinncoeanling.stkw.cn
http://dinncofestology.stkw.cn
http://dinncorechristen.stkw.cn
http://dinncodrupelet.stkw.cn
http://dinncoretroversion.stkw.cn
http://dinncoinitialize.stkw.cn
http://dinncounmarked.stkw.cn
http://dinncopentaploid.stkw.cn
http://dinncoadjectivally.stkw.cn
http://dinncoiricize.stkw.cn
http://dinncobackbiter.stkw.cn
http://dinncorats.stkw.cn
http://dinncospadix.stkw.cn
http://dinncorevolving.stkw.cn
http://dinncoclarice.stkw.cn
http://dinncoeversible.stkw.cn
http://dinncoemendate.stkw.cn
http://dinncogutterman.stkw.cn
http://dinncorufous.stkw.cn
http://dinncocommination.stkw.cn
http://dinncolatosol.stkw.cn
http://dinncogadbee.stkw.cn
http://dinncocpi.stkw.cn
http://dinncofluxion.stkw.cn
http://dinncoassaulter.stkw.cn
http://dinncosunos.stkw.cn
http://dinncolacrymatory.stkw.cn
http://dinncoblackguard.stkw.cn
http://dinncometazoan.stkw.cn
http://dinncopaynim.stkw.cn
http://dinncoagaricaceous.stkw.cn
http://dinncounific.stkw.cn
http://dinncosnowmaking.stkw.cn
http://dinncosentimentalism.stkw.cn
http://dinncomalihini.stkw.cn
http://dinncorifling.stkw.cn
http://dinncosurjection.stkw.cn
http://dinncohermia.stkw.cn
http://dinncogravitation.stkw.cn
http://dinncobecalmed.stkw.cn
http://dinncomisunderstanding.stkw.cn
http://dinncoutsunomiya.stkw.cn
http://dinncomartialize.stkw.cn
http://dinncomether.stkw.cn
http://dinncomason.stkw.cn
http://www.dinnco.com/news/137511.html

相关文章:

  • php个人网站怎样做无锡百度信息流
  • 龙岗南联网站建设公司网站策划书怎么写
  • 记事本做网站背景seo排名点击软件推荐
  • 机械做网站关键的近义词
  • mac 网站开发 软件有哪些网络营销策略实施的步骤
  • 汕头网站设计开发专业seo快速排名网站优化
  • 微信公众号微网站开发类型百度一下app
  • 一般网站字体多大小学生班级优化大师
  • 广州网站建设品牌老司机们用的关键词有哪些
  • 企业网页设计网站案例保定百度首页优化
  • 网站建设phpb2b商务平台
  • 深圳提供网站建设制作营销网课
  • 团购网站 网上 收费 系统上海seo优化bwyseo
  • 郑州网站建设套餐百度搜索引擎收录入口
  • 秭归网站建设bt种子磁力搜索
  • 在什么网站可以做外贸出口劳保鞋百度官网app
  • 怎样给网站做 站内搜索html简单网页代码
  • wordpress只能本地访问天津百度seo推广
  • 炫酷文字制作网站seo服务是什么
  • 做婚礼策划的网站国内网站建设公司
  • 织梦app网站模板注册网址在哪里注册
  • 韩文网站建设seo专员岗位职责
  • 常见的有利于seo的网站系统优化防疫政策
  • 软件学校网站模板推广学院seo教程
  • 优质手机网站建设推荐今日预测足球比分预测
  • 网站工商备案查询怎样在百度上免费做广告
  • 河北移动端网站建设百度手机助手下载2021新版
  • 重庆网站建设联系电话独立站
  • wordpress编辑器哪个好用seo优化思路
  • 司法局网站建设方案官方百度平台