#include
using namespace std;
int
main()
{
char stra[100],strb[100],str[200];//str=stra+strb
int i,j;
cout<<"Input stra(less than 100 characters):"<
cin>>stra;//cin输入字符串不要包含空格否则请用getline()
cout<<"Input strb(less than 100 characters):"<
cin>>strb;
for(i=0;stra[i]!='\0';i++)
str[i]=stra[i];
for(j=0;strb[j]!='\0';j++,i++)
str[i]=strb[j];
str[i]='\0';
cout<<"str=stra+strb="<
}
#include
using namespace std;
int main()
{
char s[100],s1[100];
cin>>s>>s1;
int i,j;
for(i = 0; s[i]; i ++);
for(j = 0; s1[j];j++)
s[i+j] = s1[j];
s[i+j] = 0;
cout <return 0;
}
你要的函数:
char* Strcat(char* str1,char* str2)
{
char *s=str1;
while(*str1)
{
str1++;
}
while(*str2)
{
*str1++=*str2++;
}
return s;
}
下面还有一些我写的函数 你可以参考下:
#include"MyString.h"
int Strcmp(char* str1, char* str2 )
{
int len1=0,len2=0;
int j=0;
char *s1,*s2;
s1=str1;
s2=str2;
while(*s1)
{
len1++;
s1++;
}
while(*s2)
{
len2++;
s2++;
}
for(int i=0; i
if(str1[i]==str2[j]){
j++;
}
else{
j=0;
}
if(j==len2){
break;
}
}
if(j==len1){
return 0;
}
else if(j==len2){
return 1;
}
else{
return -1;
}
}
int Strlen(char *str)
{
int len=0;
char *s=str;
while(*s)
{
len++;
s++;
}
return len;
}
char* Strcat(char* str1,char* str2)
{
char *s=str1;
while(*str1)
{
str1++;
}
while(*str2)
{
*str1++=*str2++;
}
return s;
}
bool IsLetter(char c)
{
return ((c>='a' && c<='z') || (c>='A' && c<='Z'));
}
bool IsLetterOrNumber(char c)
{
return ((c>='a' && c<='z') || (c>='A' && c<='Z') || (c>='0' && c<='9') );
}
bool IsNumber(char c)
{
return c>='0' && c<='9';
}
bool IsBigLetter(char c)
{
return c>='A' && c<='Z';
}
bool IsSmallLetter(char c)
{
return c>='a' && c<='z';
}
char ChangeLetter(char c)
{
if(c>='a' && c<='z'){
return c+'A'-'a';
}
else if(c>='A' && c<='Z'){
return c-'A'+'a';
}
else
{
return c;
}
}
long Pow(int num1, int num2)
{
long sum=1;
for(int i=1; i<=num2; i++)
{
sum=num1*sum;
}
return sum;
}
long atoi(char *str)
{
long num=0;
long n=0;
int len=Strlen(str);
int l=len-1;
int j=0;
for(int i=0; i
j=(int(str[i])-int('0'));
if(j>0)
{
n=j*Pow(10,l);
}
else
{
n=0;
}
num+=n;
n=0;
j=0;
l--;
}
return num;
}
char* Itoa(long num)
{
for(int i=0; i
if(Pow(10,i)>num)
break;
}
int h=num/Pow(10,i-1);
int *n=new int[i-1];
for(int j=i-1; j>=1; j--)
{
num=num%int(Pow(10,j));
n[j-1]=num/(Pow(10,j-1));
}
char *str=new char[i+1];
str[i]='\0';
str[0]=char(h+int('0'));
int m=1;
for(j=i-2; j>=0; j--)
{
num=char(n[j]+int('0'));
str[m]=char(num);
m++;
}
delete []n;
return str;
}
#include
#define Maxlength 100 //字符串最大长度
void strcat(char str1[],char str2[])
{//字符串连接
int i=-1,j=0;
while(str1[++i]!='\0');//查找字符串1的末尾
while(str2[j]!='\0')str1[i++]=str2[j++];//将字符串2连接到字符串1的后面
str1[i]='\0';//存入结束符
}
void main()
{
char str1[2*Maxlength],str2[Maxlength];
gets(str1);//输入字符串1
gets(str2);//输入字符串2
strcat(str1,str2);//连接字符串
puts(str1);//输出连接后的字符串
}