第16周 项目2-用指针玩字符串(1)
来源:互联网 发布:mac office 预览选项 编辑:程序博客网 时间:2024/05/23 19:14
代码:
/* * Copyright (c) 2014, 烟台大学计算机学院 * All rights reserved. * 文件名称:test.cpp * 作 者:阿里木·阿布都热合曼 * 完成日期:2014年 12 月 15 日 * 版 本 号:v1.0 * * 问题描述:用数组名作形参方案,其核心是实现char *astrcat(char str1[], const char str2[])//字符串连接函数实现和测试示例 * 输入描述: * 程序输出: */ #include <iostream>using namespace std;char *astrcat(char str1[], const char str2[]);int main(){ char s1[50]="Hello world. "; char s2[50]="I am student. "; char s3[50]="An good student. "; astrcat(s1,s2); cout<<"连接后:"<<s1<<endl; cout<<"连接后:"<<astrcat(s2,s3)<<endl; //返回值为char*型,可以直接显示 return 0;}char *astrcat(char str1[], const char str2[]){ int i,j; for(i=0; str1[i]!='\0'; i++) for(j=0; str2[j]!='\0'; i++,j++) { str1[i]=str2[j]; } str1[i]='\0'; return str1;
}
运行结果:
<img width="669" height="430" style="width: 1015px; height: 359px;" src="http://img.blog.csdn.net/20141215104304601?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvYWxpbTEzMTQ1MjBu/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="" />
0 0
- 第16周 项目2-用指针玩字符串(1)
- 第16周项目2 用指针玩字符串2
- 第16周项目2(4)-用指针玩字符串
- 第16周项目2(5)-用指针玩字符串
- 第16周项目2(6)-用指针玩字符串
- 第16周项目2(7)-用指针玩字符串
- 第16周项目2-用指针玩字符串
- 第16周【项目 2-用指针玩字符串】①
- 第16周【项目 2-用指针玩字符串】②
- 第16周【项目 2-用指针玩字符串】③
- 第16周【项目 2-用指针玩字符串】④
- 第16周【项目 2-用指针玩字符串】⑤
- 第16周【项目 2-用指针玩字符串】⑥
- 第16周【项目 2-用指针玩字符串】⑦
- 第16周项目2 用指针玩字符串
- 第16周项目2 用指针玩字符串3
- 第16周项目2 用指针玩字符串4
- 第16周项目2-用指针玩字符串(1)字符串连接
- Hibernate学习笔记——log4j及JUnit的配置
- aar格式
- php 接口
- 第十六周项目三用函数指针调用函数
- hdu 4406 GPA 费用流
- 第16周 项目2-用指针玩字符串(1)
- 23种设计模式-11-责任连模式
- Java浮点数为什么精度会丢失
- c++关于字符串的替换
- 解决https证书导入路径有空格问题
- 第16周项目3-用函数指针调用函数
- 04分布式NOSQL HBASE - HBase过滤器
- 16周(oj 3)
- hdu 4309 Seikimatsu Occult Tonneru 枚举+最大流