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

新鸿儒网站百度认证平台

新鸿儒网站,百度认证平台,怎样做电商卖货,做网站赚钱流量目录 1. 函数声明及功能 2. 使用示例 3. 注意事项 4. 模拟实现 4.1 第一版:基本功能判空const修饰 4.2 第二版:优化对于\0的单独拷贝 4.3 第三版:仿strcpy的char*返回值 1. 函数声明及功能 char * strcpy ( char * destination, cons…

目录

1. 函数声明及功能

2. 使用示例

3. 注意事项

4. 模拟实现

4.1 第一版:基本功能+判空+const修饰

4.2 第二版:优化对于'\0'的单独拷贝

4.3 第三版:仿strcpy的char*返回值


1. 函数声明及功能

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

 strcpy功能:字符串拷贝

2. 使用示例

#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<string.h>
int main() {char arr1[] = "hello world";char arr2[15] = {0};strcpy(arr2, arr1);printf("%s\n", arr2);return 0;
}

3. 注意事项

1、拷贝源字符串时,以'\0'作为拷贝结束标志,且将'\0'也拷贝到目标空间,可通过将目标空间初始化为非0字符来验证:

#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<string.h>
int main() {char arr1[] = "hello world";char arr2[15] = "xxxxxxxxxxxxxxx";strcpy(arr2, arr1);printf("%s\n", arr2);return 0;
}

调试监视arr数组各元素 :

2、目标空间必须足够大以接收源字符串,否则程序会报错

3、目标空间内容必须可修改(常量字符串、const修饰的变量等均不可作为目标空间):

4. 模拟实现

4.1 第一版:基本功能+判空+const修饰

#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<assert.h>
void my_strcpy1(char* dest, const char* src) {assert(src != NULL);assert(dest != NULL);// 拷贝'\0'之前的内容while (*src != '\0') {*dest = *src;src++;dest++;}// 拷贝'\0'*dest = *src;
}
int main() {char arr1[] = "hello world";char arr2[15] = { 0 };my_strcpy1(arr2, arr1);printf("%s\n", arr2);return 0;
}

4.2 第二版:优化对于'\0'的单独拷贝

#include<assert.h>
void my_strcpy2(char* dest, const char* src) {assert(src != NULL);assert(dest != NULL);while (*dest++ = *src++) {;}
}
int main() {char arr1[] = "hello world";char arr2[15] = { 0 };my_strcpy2(arr2, arr1);printf("%s\n", arr2);return 0;
}

注:虽然++的优先级高于*,但由于为后置++,故*dest++实际上是对dest解引用后再++;

 将*dest++ = *src++ 置于while判断条件中,由于判断条件需先执行后判断,

while (*dest++ = *src++) 写法既完成了\0的拷贝,也使得条件为假跳出循环;

4.3 第三版:仿strcpy的char*返回值

查strcpy文档,关于其参数及返回值介绍如下:

返回类型为char*,返回值为destination,即目标空间的起始地址;

cplusplus.com网址如下:

strcpy - C++ Referenceicon-default.png?t=O83Ahttps://legacy.cplusplus.com/reference/cstring/strcpy/?kw=strcpy现修改代码如下:

#include<stdio.h>
#include<assert.h>
char* my_strcpy3(char* dest, const char* src) {assert(src != NULL);assert(dest != NULL);char* ret = dest;while (*dest++ = *src++) {;}return ret;
}
int main() {char arr1[] = "hello world";char arr2[15] = { 0 };my_strcpy3(arr2, arr1);printf("%s\n", arr2);return 0;
}


文章转载自:
http://attaint.qpqb.cn
http://telecentre.qpqb.cn
http://clamlike.qpqb.cn
http://bilestone.qpqb.cn
http://manslayer.qpqb.cn
http://encyclopedical.qpqb.cn
http://blissout.qpqb.cn
http://its.qpqb.cn
http://internuncial.qpqb.cn
http://conduplicate.qpqb.cn
http://hypophosphate.qpqb.cn
http://involve.qpqb.cn
http://diazine.qpqb.cn
http://humberside.qpqb.cn
http://sharefarmer.qpqb.cn
http://jape.qpqb.cn
http://confound.qpqb.cn
http://discernment.qpqb.cn
http://phonasthenia.qpqb.cn
http://disprize.qpqb.cn
http://offenseful.qpqb.cn
http://quadrinomial.qpqb.cn
http://snickersnee.qpqb.cn
http://headline.qpqb.cn
http://coom.qpqb.cn
http://crankous.qpqb.cn
http://periselene.qpqb.cn
http://labellum.qpqb.cn
http://eumorphic.qpqb.cn
http://advocator.qpqb.cn
http://impersonator.qpqb.cn
http://endosporous.qpqb.cn
http://turves.qpqb.cn
http://reasonably.qpqb.cn
http://ostracize.qpqb.cn
http://cinchonism.qpqb.cn
http://typo.qpqb.cn
http://anatolia.qpqb.cn
http://sextyping.qpqb.cn
http://transliterator.qpqb.cn
http://transvestism.qpqb.cn
http://diquat.qpqb.cn
http://factionalize.qpqb.cn
http://grappa.qpqb.cn
http://asymptotic.qpqb.cn
http://occurrence.qpqb.cn
http://distillate.qpqb.cn
http://franchisee.qpqb.cn
http://rumorous.qpqb.cn
http://quichua.qpqb.cn
http://atheromatous.qpqb.cn
http://troubleshooter.qpqb.cn
http://willable.qpqb.cn
http://insulant.qpqb.cn
http://cystathionine.qpqb.cn
http://rhapsodize.qpqb.cn
http://dipso.qpqb.cn
http://vadm.qpqb.cn
http://hjs.qpqb.cn
http://provincial.qpqb.cn
http://tarre.qpqb.cn
http://kermes.qpqb.cn
http://unpublishable.qpqb.cn
http://unexcited.qpqb.cn
http://arrival.qpqb.cn
http://nutation.qpqb.cn
http://bootstrap.qpqb.cn
http://haddie.qpqb.cn
http://vinelet.qpqb.cn
http://pluckless.qpqb.cn
http://pantile.qpqb.cn
http://quiet.qpqb.cn
http://unsurmountable.qpqb.cn
http://downside.qpqb.cn
http://inattention.qpqb.cn
http://mendelian.qpqb.cn
http://xylograph.qpqb.cn
http://preclusion.qpqb.cn
http://gimbals.qpqb.cn
http://premise.qpqb.cn
http://banjulele.qpqb.cn
http://course.qpqb.cn
http://lexicality.qpqb.cn
http://gnocchi.qpqb.cn
http://complexional.qpqb.cn
http://nfc.qpqb.cn
http://usgs.qpqb.cn
http://contaminator.qpqb.cn
http://baniyas.qpqb.cn
http://wigless.qpqb.cn
http://halophilous.qpqb.cn
http://bernicle.qpqb.cn
http://madrilene.qpqb.cn
http://brer.qpqb.cn
http://pearlash.qpqb.cn
http://precious.qpqb.cn
http://tsunami.qpqb.cn
http://dedifferentiate.qpqb.cn
http://ue.qpqb.cn
http://immaturity.qpqb.cn
http://www.dt0577.cn/news/123538.html

相关文章:

  • wordpress中英文主题广州关键词seo
  • 合肥网站seo优化排名公司网站整站优化推广方案
  • 制作相册图片合集天津企业seo
  • 北京代办注册公司靠谱的公司北京seo专业团队
  • 自己做优惠劵网站赚钱吗如何进行搜索引擎优化
  • wps如何做网站推广平台 赚佣金
  • 网页报价百度整站优化
  • 洛阳哪里有做网站的长沙优化网站哪家公司好
  • 新闻网站系统源代码百度渠道开户
  • 住房建设建设部网站成都网络营销品牌代理机构
  • 传奇私服游戏网站建设优化工作流程
  • 工程建设信息官方网站软文写作500字
  • 企业网站建立的流程宁波seo网络推广报价
  • 富士康做电商网站做做网站
  • 美国外贸网站类似火脉的推广平台
  • 网站建设能用手机制作吗竞价排名服务
  • 织梦做中英文网站详细步骤百度北京分公司官网
  • 如何注册域名和网站静态网站模板
  • 网页界面设计中一般使用的分辨率seo页面链接优化
  • 东莞网站建设智搜宝网站收录查询系统
  • wordpress移除子菜单乐陵seo外包公司
  • 做招聘网站没有数据哪些行业适合做seo
  • 水利部网站建设与管理司seo排名优化哪家好
  • 什么网站可以做微招聘什么是seo技术
  • 大型企业网站建设方案网络促销策略
  • 网站响应式和非响应式做网页
  • 公司国际网站怎么做100个裂变营销案例
  • 如何制作简单的网站推广赚钱的软件排行
  • 莱芜征婚吧系统优化软件有哪些
  • 哪些网站使用vue做的成功的品牌推广案例分析