AIR

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include <iostream>
using namespace std;
#include <string.h>
void Myappend(char t1[],char t2[]);//用于连接字符串的函数
int my_strlen(const char *str);//用于计算字符数组的长度
int main()
{
char a[20],b[20];//定义数组用于储存字符串

cout<<"Please enter a string:"<<endl;
cin>>a;
cout<<"Please enter a string:"<<endl;
cin>>b;
Myappend(a,b);
return 0;
}


void Myappend(char t1[],char t2[])
{
int len1,len2;
len1=my_strlen(t1);
len2=my_strlen(t2);//获得字符串长度
for(int i=0; i<=len2; i++)
t1[len1+i]=t2[i];//将b字符串的头部赋给a字符串的尾部,并依此赋值
cout<<t1<<endl;

}
int my_strlen(const char *str)
{
int count =0;
while(*str !='\0')
{
count++;
str++;
}
return count;
}

 Comments


Blog content follows the Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0) License

Use Material X as theme , total visits times .
载入天数...载入时分秒...