今天看完机器学习的课程后,就换C语言学习了一下。也是第一次接触strcat函数 ——字符串连接函数。它的一般形式为strcat(字符数组1,字符数组2) 。其作用是把两个字符数组中的字符串连接起来,把字符串2接到字符串1的后面,结果放在字符数组1中,函数调用后得到一个函数值——字符数组1的地址。例如:

#include<stdio.h>
int main()
{
	char str1[30] = {"People's Republic of "};
	char str2[] = {"China"};
	printf("%s",strcat(str1,str2));
	
	return 0;
}

输出代码报错:

In function 'main':
[Warning] incompatible implicit declaration of built-in function 'strcat'

百度了一下原因,少加了头文件

#include<stdlib.h>

#include<string.h>

加入之后,程序正常输出:
[Warning] incompatible implicit declaration of built-in function 'strcat'

相关文章: