char *strcat(char *s, char *t)

char *strcat(char *s, char *t)

把*t连接到*s,并保存在*s中,*s没有足够空间的话,编译器找不到这个小虫子,gdb也没有发现它,一运行它就钻出来…

一个可行的方案:

#include
#include

#define MAX_NUM 100

int main()
{
	char fn[MAX_NUM];
	char *s = "abc";
	char *t = "def";

	strcpy(fn, s);
	strcat(fn, t);

	printf("%s\n", fn);

	return 0;
}

另一个似乎也不错:

#include

#define MAX_NUM 100

int main()
{
	char fn[MAX_NUM];
	char *s = "abc";
	char *t = "def";

	sprintf(fn, "%s%s", s, t);

	printf("%s\n", fn);

	return 0;
}
updatedupdated2022-02-222022-02-22