
题目

解决代码及点评
/*
5.  写一函数,将两个字符串连接,即编写一strcat函数。
*/
void stract(char *p1,char *p2,int n,int count1,int count2)//字符串链接函数
{
  if (n<count1+count2+1)
  {
    printf("第一个字符串长度不够");
  }
  else
  {
    count2=0;
    while(p1[count1++]=p2[count2++]);
  }
}
void main()
{
  char str1[50]="abcdefghijk";
  char str2[]="1234567890";
  int count1=0;//记录第一个字符串长度
  int count2=0;//记录第二个字符串长度
  while(str1[count1]) count1++;
  while(str2[count2]) count2++;
  int n=sizeof(str1);//计算数组一的字节数
  stract(str1,str2,n,count1,count2);
  printf("%s",str1);
  system("pause");
}代码编译以及运行
由于资源上传太多,资源频道经常被锁定无法上传资源,同学们可以打开VS2013自己创建工程,步骤如下:
1)新建工程

2)选择工程

3)创建完工程如下图:

4)增加文件,右键点击项目

5)在弹出菜单里做以下选择

6)添加文件

7)拷贝代码与运行

程序运行结果











