第十六周项目2-用指针玩字符串(连接字符串)
来源:互联网 发布:美国网站域名后缀 编辑:程序博客网 时间:2024/06/05 04:26
/* *Copyright(c)2014,烟台大学计算机学院 *All rights reserved. *文件名称:test.cpp *作者:梁璨 *完成日期:2014年 12月 13日 *版本号:v1.0/ *
</pre><pre class="cpp" name="code">#include <iostream>using namespace std;char *pstrcat(char *str1,const char *str2);int pstrlen(char *str);int main(){ char s1[50]="Hello world. "; char s2[50]="Good morning. "; char s3[50]="vegetable bird! "; pstrcat(s1,s2); cout<<"连接后:"<<s1<<endl; cout<<"连接后:"<<pstrcat(s2,s3)<<endl; return 0;}char *pstrcat(char *str1, const char *str2){ char *p; //char *q=str2; //如果这样会出现错误,如何改程序,可有多种改法 int i; for(p=str1; *p!='\0'; p++); //找到str1的结束 for(i=0; *(str2+i)!='\0'; i++,p++) //如果q的定义通过,可以用*(q+i)代替*(str2+i) { *p=*(str2+i); } *p='\0';//切记!! return str1;}运行结果:
0 0
- 第十六周项目2-用指针玩字符串(示例:任务一:连接字符串)
- 第十六周项目2-用指针玩字符串(连接字符串)
- 第十六周项目2-用指针玩字符串(一)
- 第十六周项目2-用指针玩字符串(二)
- 第十六周项目2-用指针玩字符串(补充)
- 第十六周 项目二--用指针玩字符串(2.1.2用指针作形参,连接字符串str1和str2)
- 第十六周项目 2 用指针玩字符串——连接两个字符串
- 第十六周项目二:用指针玩字符串(一):字符串连接任务
- 第十六周项目2-用指针玩字符串2
- 第十六周项目2-用指针玩字符串
- 第十六周项目2-用指针玩字符串
- 第十六周项目 2 用指针玩字符串
- 第十六周项目二用指针玩字符串-2
- d第十六周上机项目2 用指针玩字符串
- 第十六周项目二(二):用指针玩字符串
- 第十六周项目二用指针玩字符串任务一:字符串连接的完成(用指针作形参)
- 第十六周项目2-用指针玩字符串(任务三:求字符串长度)
- 第十六周项目2-用指针玩字符串(去除字符串中的特定字符)
- 在你的应用程序添加启动画面
- 简单工厂模式
- LinkedHashMap和HashMap的比较使用
- struts2 拦截器和actioninvocation
- 窗口重绘一点通
- 第十六周项目2-用指针玩字符串(连接字符串)
- 如何设置JTable不可编辑
- BDTC2014中国大数据技术大会 会议记录
- C语言大世界—————09指针类型之函数指针+函数别名 福利篇
- 自己写的detab函数
- Linux epoll工作原理
- linux0.11任务切换switch_to
- 面向对象与面向过程小结
- JScrollPane,JTable