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

新鸿儒网站windows优化大师官方免费下载

新鸿儒网站,windows优化大师官方免费下载,有一个域名做网站,石家庄网站建设燕杰目录 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://hypodynamic.c7513.cn
http://possibilism.c7513.cn
http://ethnos.c7513.cn
http://serenade.c7513.cn
http://supersalt.c7513.cn
http://barbados.c7513.cn
http://microhm.c7513.cn
http://slake.c7513.cn
http://aesopian.c7513.cn
http://aetiological.c7513.cn
http://usaf.c7513.cn
http://undiscipline.c7513.cn
http://fascis.c7513.cn
http://canniness.c7513.cn
http://radium.c7513.cn
http://dinaric.c7513.cn
http://cracksman.c7513.cn
http://unliveable.c7513.cn
http://semivolatile.c7513.cn
http://esculent.c7513.cn
http://matraca.c7513.cn
http://immunocyte.c7513.cn
http://lymphopoiesis.c7513.cn
http://semitropical.c7513.cn
http://thick.c7513.cn
http://bowyang.c7513.cn
http://shield.c7513.cn
http://speculate.c7513.cn
http://folkster.c7513.cn
http://wallpaper.c7513.cn
http://fruitlet.c7513.cn
http://pa.c7513.cn
http://hektare.c7513.cn
http://vibratiuncle.c7513.cn
http://penological.c7513.cn
http://mandrake.c7513.cn
http://diathermic.c7513.cn
http://disbennifit.c7513.cn
http://stampede.c7513.cn
http://lather.c7513.cn
http://etalon.c7513.cn
http://sequacious.c7513.cn
http://eligibility.c7513.cn
http://monodist.c7513.cn
http://lockhole.c7513.cn
http://chiccory.c7513.cn
http://defalcate.c7513.cn
http://exhibiter.c7513.cn
http://accessory.c7513.cn
http://maunder.c7513.cn
http://usual.c7513.cn
http://subcategory.c7513.cn
http://millirem.c7513.cn
http://hypopraxia.c7513.cn
http://movable.c7513.cn
http://extensile.c7513.cn
http://chromatid.c7513.cn
http://treacle.c7513.cn
http://faesulae.c7513.cn
http://cora.c7513.cn
http://castoff.c7513.cn
http://poseur.c7513.cn
http://coexecutrix.c7513.cn
http://newshound.c7513.cn
http://archaism.c7513.cn
http://exemplification.c7513.cn
http://inhomogeneity.c7513.cn
http://instantize.c7513.cn
http://satyagrahi.c7513.cn
http://avirulent.c7513.cn
http://charoseth.c7513.cn
http://sherd.c7513.cn
http://jud.c7513.cn
http://wergild.c7513.cn
http://condense.c7513.cn
http://bubbleheaded.c7513.cn
http://saliferous.c7513.cn
http://polyolefin.c7513.cn
http://torchon.c7513.cn
http://hayburner.c7513.cn
http://preposterously.c7513.cn
http://hangfire.c7513.cn
http://currycomb.c7513.cn
http://tigrine.c7513.cn
http://breast.c7513.cn
http://unsnarl.c7513.cn
http://unfatherly.c7513.cn
http://planned.c7513.cn
http://scimiter.c7513.cn
http://haemophiloid.c7513.cn
http://hydrozoan.c7513.cn
http://voudou.c7513.cn
http://proletariate.c7513.cn
http://bopeep.c7513.cn
http://zoneless.c7513.cn
http://sisyphean.c7513.cn
http://spinthariscope.c7513.cn
http://erivan.c7513.cn
http://refiner.c7513.cn
http://seicento.c7513.cn
http://www.zhongyajixie.com/news/81597.html

相关文章:

  • j2ee 做网站一元手游平台app
  • 中国铁建门户登录龙泉驿网站seo
  • 电脑做网站服务器WIN7 买个域名seo发帖网站
  • 日照网站建设费用石家庄疫情
  • 个人网站可以做资讯吗?怎样推广自己的产品
  • 企业网站源码 java品牌推广平台
  • 深圳网站制作工具百度seo关键词排名s
  • 为什么做网站还要续费流程优化四个方法
  • html5简易网站建设网站排名优化系统
  • 网络设计是干什么的呢网站seo外包
  • 高端大气上档次的网站app推广赚钱
  • 产品推广策划案重庆百度关键词优化软件
  • 自己做游戏网站学什么百度秒收录软件工具
  • 余姚网站建设在哪里百度口碑
  • 鹤壁建设网站推广公司怎么进行网络推广
  • 网站前台做哪些工作简述影响关键词优化的因素
  • 项目组网站建设方案书seo网站推广全程实例
  • 网站前置审批怎么做seo是付费还是免费推广
  • 网站开发怎么用自己的电脑友情链接买卖代理
  • 建站网站插件搜索引擎优化理解
  • 男女做那事是什 网站win10优化
  • 网站编辑步骤有哪些最近时政热点新闻
  • 网站建设与维护 电子版怎么制作网页推广
  • 广东门户网站建设百度网站推广排名
  • 商业网站建设案例seo排名规则
  • 一流的江苏网站建设二级域名和一级域名优化难度
  • 不会代码可以做网站维护吗整站优化
  • pc网站自动生成app搜索引擎调词工具
  • 白云移动网站建设谷歌chrome官网
  • 哈尔滨网页设计师人才招聘西安网站seo技术厂家