第十七周-项目二(1)字符串str1与str2的链接。(数组法)

来源:互联网 发布:织撒网数据参数 编辑:程序博客网 时间:2024/06/01 10:34
/*02.* 程序的版权和版本声明部分03.* Copyright (c)2013, 烟台大学计算机学院学生04.* All rightsreserve05.* 文件名称: array.cpp06.* 作    者:  王洪海07.* 完成日期:  2013年 12月 21日08.* 版本号: v1.009.* 输入描述:无10.* 问题描述:*/#include <iostream>using namespace std;void  astrcat(char str1[],const char str2[]);int geshu(char str3[]);int main(){    char s1[50]={"Hello world ."};    char s2[50]={"Good morning!"};    astrcat (s1,s2);    cout<<"连接后:"<<endl;    cout<<s1<<endl;    return 0;}void  astrcat(char str1[],const char str2[]){    int i,j,n;    n=geshu(str1);    for(i=n;str1[i]!='\0';i++)    for(j=0;str2[j]!='\0';i++,j++)    {        str1[i]=str2[j];    }    str1[i]='\0';    return;} int geshu(char str3[]){    int k,m;    for(k=0;str3[k]!='\0';)      {           m=k;           k++;      }    return m;}

运行结果,如图:


0 0
原创粉丝点击