标签:
1 写出函数,相当于strncat
1 #define _CRT_SECURE_NO_WARNINGS 2 3 #include<stdio.h> 4 #include<stdlib.h> 5 #include<string.h> 6 7 void mystrncat(char *bc, char *c, int length) 8 { 9 if (bc == NULL || c == NULL) 10 { 11 return NULL; 12 } 13 else 14 { 15 int i; 16 char *p = bc; 17 while (*p != ‘\0‘) 18 { 19 p++; 20 } 21 //p指向了字符串的末端‘\0‘ 22 for (i = 0;i < length;i++)//前进length个字符 23 { 24 *p = c[i];//赋值 25 p++;//指针前进,遍历 26 } 27 } 28 } 29 30 main() 31 { 32 char str[30] = "task"; 33 char str1[30] = "list8848"; 34 35 puts(str); 36 37 mystrncat(str, str1, 4); 38 39 puts(str); 40 41 system(str); 42 43 system("pause"); 44 }
标签:
原文地址:http://www.cnblogs.com/denggelin/p/5507395.html