天天看點

C語言中strcpy與strcat的使用

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
void main()
{   char p[20]={'a','b','c','d'},q[]="abc",r[]="abcde";
    strcat(p,r);
	printf("p=%s\n",p);

	strcpy(p+2,q);   //将q的值指派到p中,p+2表示保留2個字元

	printf("p=%s",p);
	system("pause");
}
           

1.strcpy在使用中指派是将所有的字元串均複制過去,strcpy(p+2,q),p+2表示p中字元保留個數。

2.strcat(p,r)表示p字元串後面拼接r字元串。