这个函数的主要作用就是将两个字符串内的数据进行连接,形成一个新的字符串,直接看代码.
如下面例题:
#define _CRT_SECURE_NO_WARNINGS#include<stdio.h>#include<stdlib.h>#include<string.h>#include <assert.h>//====strcat函数实例(连接)char* strcat(char* dest, const char* source){if (dest == NULL || source == NULL){//合法性校验return dest;}char* p = dest;//将目的数组赋给pwhile (*p != ' '){//循环看大小p++;}while (*source != ' '){//注意指针的用法*p = *source;p++;//依次加加进行连接source++;}*p = ' ';return dest;}int main(){char arr1[1024] = "good";strcat(arr1, "job");//这里直接调用函数,后置位直接写字符串即可printf("%sn", arr1);//输出system("pause");return 0;}函数内部的代码就是明显的利用了’ ’的作用,将函数挨个进行遍历,最终实现对应的作用.