第16周项目2-用指针玩字符串(1)字符串连接
来源:互联网 发布:免费内部通讯软件 编辑:程序博客网 时间:2024/05/22 11:27
/* *Copyright (c) 2014,烟台大学计算机学院 *All rights reserved. *文件名称:Annpion.cpp *作者:王耀鹏 *完成日期:2014年12月15日 *版本号:v1.0 * *问题描述:用指针玩字符串。 *输入描述:不输入。 *程序输出:字符串连接。 */ #include <iostream>using namespace std;char *astrcat(char str1[], const char str2[]);int main(){ char s1[50]="Hello world. "; char s2[50]="Good morning. "; char s3[50]="vegetable bird! "; astrcat(s1,s2); cout<<"连接后:"<<s1<<endl; cout<<"连接后:"<<astrcat(s2,s3)<<endl; //返回值为char*型,可以直接显示 return 0;}//作为示例,本函数采用了形参为数组,在实现中,直接用下标法进行访问//实际上,在实现中,完全可以用指针法访问char *astrcat(char str1[], const char str2[]){ int i,j; //请理解:以下所有str1[i]可以替换为*(str1+i),str2[j]可以…… for(i=0; *(str1+i)!='\0'; i++); //找到str1的结束 for(j=0; *(str2+j)!='\0'; i++,j++) { *(str1+i)=*(str2+j); } *(str1+i)='\0';//切记!! return str1;}
运行结果:
0 0
- 第16周项目2-用指针玩字符串(1)字符串连接
- 第16周项目2-用指针玩字符串(字符串连接)
- 第16周项目2--用指针玩字符串(实现字符串的连接)
- 第16周项目2-用指针玩转字符串-(1.1)字符串连接
- 第16周项目2-用指针玩转字符串-(1.2)字符串连接
- 第16周 项目2-用指针玩字符串(1)
- C++第17周项目2——用指针玩字符串(1)连接
- 第17周项目2--用指针玩字符串1(将两个字符串连接,连接后的结果存放在字符串1中)
- 第十七周项目2-用指针玩字符串(连接)
- 第16周项目2 用指针玩字符串2
- 第16周项目2(4)-用指针玩字符串
- 第16周项目2(5)-用指针玩字符串
- 第16周项目2(6)-用指针玩字符串
- 第16周项目2(7)-用指针玩字符串
- 第16周项目2-用指针玩字符串
- 第16周【项目 2-用指针玩字符串】①
- 第16周【项目 2-用指针玩字符串】②
- 第16周【项目 2-用指针玩字符串】③
- python mysql结果查询
- 易语言 TCP支持库
- 二进制在数学中的妙用(转帖)
- 黑马程序员——Foundation框架——NSString
- csdn站内搜索结果爬虫
- 第16周项目2-用指针玩字符串(1)字符串连接
- (下拉框系列1)下拉框Html.DropDownList 和DropDownListFor 的常用方法
- Mysql无法创建外键的原因
- KNN(k近邻算法)
- (下拉框系列2)MVC中下拉框显示枚举项
- B树
- 搜索引擎-倒排索引
- Mac下终端(Terminal)快捷键
- http://wiki.openwrt.org/doc/techref/hotplug