#define  _CRT_SECURE_NO_WARNINGS
#include <stdlib.h>
#include <string.h>
#include <stdio.h> void main71()
{
char a[] = "i am a student";
char b[64];
int i = 0; for (i=0; *(a+i) != '\0'; i++)
{
*(b+i) = *(a+i);
} //0没有copy到b的buf中. b[i] = '\0'; //重要
printf("a:%s \n", a);
printf("b:%s \n", b); system("pause");
return ;
} //字符串copy函数技术推演 //字符串copy函数 //form形参 形参to 的值 不停的在变化....
//不断的修改了from和to的指向
void copy_str21(char *from, char *to)
{
for (; *from!='\0'; from++, to++)
{
*to = *from;
}
*to = '\0'; return ;
} //*操作 和++的操作
//++ 优先级高
void copy_str22(char *from, char *to)
{
for (; *from!='\0';)
{
*to++ = *from++; // 先 *to = *from; 再from++, to++
}
*to = '\0'; // return ;
} void copy_str23(char *from, char *to)
{
while( (*to = *from) != '\0' )
{
from ++;
to ++;
}
} void copy_str24(char *from , char *to)
{
while ( (*to++ = *from++) != '\0')
{
;
}
} void copy_str25(char *from , char *to)
{
//*(0) = 'a';
while ( (*to++ = *from++) )
{
;
}
} void copy_str25_err(char *from , char *to)
{
//*(0) = 'a';
while ( (*to++ = *from++) )
{
;
} printf("from:%s \n", from); } //不要轻易改变形参的值, 要引入一个辅助的指针变量. 把形参给接过来.....
int copy_str26_good(char *from , char *to)
{
//*(0) = 'a';
char *tmpfrom = from;
char *tmpto = to;
if ( from == NULL || to == NULL)
{
return -1;
} while ( *tmpto++ = *tmpfrom++ ) ; //空语句 printf("from:%s \n", from); } int main111()
{
int ret = 0;
char *from = "abcd";
char buf2[100];
//copy_str21(from, buf2);
//copy_str22(from,buf2);
//copy_str23(from, buf2);
//copy_str24(from, buf2);
//copy_str25(from ,buf2);
//printf("buf2:%s \n", buf2); {
//错误案例
char *myto = NULL; //要分配内存
//copy_str25(from,myto );
}
{
char *myto = NULL; //要分配内存 ret = copy_str26_good(from, myto);
if (ret != 0)
{
printf("func copy_str26_good() err:%d ", ret);
return ret;
}
}
system("pause");
return ret;
} int main777()
{
int ret = 0;
char *from = "abcd";
char buf2[100]; printf("copy_str25_err begin\n");
copy_str25_err(from, buf2);
copy_str26_good(from, buf2);
printf("copy_str25_err end\n");
return 0;
}

最新文章

  1. SVN本地代码未提交而被覆盖
  2. C++程序设计——知识点总结
  3. leancloud 用户登录(调用API) 教程
  4. 误人子弟的网络,谈谈HTTP协议中的短轮询、长轮询、长连接和短连接
  5. [Python] Remote debugging by Pycharm
  6. [Cocos2d-x For WP8]基础知识
  7. windows下 Python 安装包的配置
  8. iis7.0/8.0rewrite规则
  9. Myeclipse 搭建Java Web 项目 《一》
  10. vue setTimeout用法 jquery滚动到某一个div的底部
  11. vue2.0 项目build后资源文件报错404的解决方案
  12. JavaScript的数据结构和算法
  13. C#串口通信:2自动连接
  14. input 标签的 disabled 和 readonly 属性
  15. Beta冲刺 (7/7)
  16. bozoj3131: [Sdoi2013]淘金 数位dp
  17. P2375 [NOI2014]动物园
  18. [UE4]GameMode和GameInstance
  19. java配置slf4j日志系统
  20. python--第七天总结

热门文章

  1. HashMap?ConcurrentHashMap?
  2. 面试问题之C++语言:mutable关键字
  3. springboot-@EventListener简单用法
  4. 用 wait-notify 写一段代码来解决生产者-消费者问题?
  5. 用纯CSS实现优雅的tab页
  6. 体验javascript之美第五课 五分钟彻底明白 匿名函数自执行和闭包
  7. 微信小程序自定义tab,多层tab嵌套实现
  8. 重磅:前端 MVVM 与 FRP 的升阶实践 —— ReRest 可视化编程
  9. numpy教程02---ndarray数据和reshape重塑
  10. python---插入排序的实现