第十六周项目二:用指针玩字符串(一):字符串连接任务

来源:互联网 发布:js怎么获取鼠标位置 编辑:程序博客网 时间:2024/06/05 05:29
/**copyright (c) 2014, 烟台大学计算机学院.*All rights reserved.*文件名称:test.cpp *作者:陆云杰*完成日期:2014年12月10日 *版本号: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;    for(i=0; *(str1+i)!='\0'; i++);    for(j=0; *(str2+j)!='\0'; i++,j++)    {        str1[i]=str2[j];    }    str1[i]='\0';//切记!!    return str1;}

学习心得:又进步啦!

0 0
原创粉丝点击