请大家看看 我这个函数的串连接功能为什么不能实现!
#include<stdio.h>#include<stdlib.h>
#include <string.h>
#define MAXLEN 100
typedef struct
{char vec[MAXLEN];
int len;
}str;
int i,j,k;
int lenstr(str *r)
{int i=0;
while(r->vec[i]!='\0')
i++;
return i;
}
char concatstr(str *r1,str *r2)
{if(r1->len+r2->len>MAXLEN)
printf("两个串太长,溢出!");
else
{for(i=0;i<r2->len;i++)
r1->vec[r1->len+i]=r2->vec[i];
r1->vec[r1->len+i]='\0';
r1->len=r1->len+r2->len;
}
return r1->vec;
}
void main()
{int i;
int j;
int k;
str *r;
str *r1;
str *r2;
r=malloc(sizeof(str));
r1=malloc(sizeof(str));
r2=malloc(sizeof(str));
r->len=0;
r1->len=0;
r2->len=0;
gets(r->vec);
gets(r1->vec);
printf("第一个长为%d\n",lenstr(r));
printf("第二个长为%d\n",lenstr(r1));
concatstr(r,r1);
printf("连接后的串为");
puts(r->vec);
}