17--2--1连接1,2字符串后放在1中。

来源:互联网 发布:什么软件用网络打电话 编辑:程序博客网 时间:2024/04/30 15:18
/** Copyright (c) 2013, 烟台大学计算机学院* All rights reserved.* 作    者:纪丽娜* 完成日期:2013 年  12月* 版 本 号:v1.0* 问题描述:字符串str1和str2连接,连接后的结果存放到str1中!*/#include <iostream>using namespace std;void astrcat(char str1[],const char str2[]);int main(){    char a[50]="Hello";    char b[50]=" world";    astrcat(a,b);    cout<<"连接后:"<<a<<endl;    return 0;}void astrcat(char str1[],const char str2[]){    int i,j;    for(i=0;str1[i]!='\0';i++);   //找到str1的末尾    for(j=0;str2[j]!='\0';i++,j++)    {        str1[i]=str2[j];    }    str1='\0';}

0 0
原创粉丝点击