字符串的追加

#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<time.h>

//使用系统提供的函数strcat、strncat

int main0101()

{

  char dest[100]="hello";

  char src[]="world";

//字符串追加

  //strcat(dest,src);

//字符串有限追加

  strncat(dest,src,3);//hellowor

  printf("%s ",dest);

  return EXIT_SUCCESS;

}

//自定义函数

//字符串追加

void my_strcat01(char*dest,char*src)

{

//找到dest字符串中的位置

  while(*dest)dest++;

  while(*dest++=*src++);

}

//字符串有限追加

void my_strcat(char*dest,char*src,size_t n)

{

  while(*dest)dest++;

  while((*dest++=*src++&&--n);

}

int main(void)

{

  char dest[100]="hello";

  char src[]="world";

//字符串追加

  //my_strcat(dest,src);

//字符串有限追加

  my_strncat(dest,src,3)//hellowor

}

原文地址:https://www.cnblogs.com/wanghong19991213/p/13610320.html