繁体   English   中英

警告:function 'strcpy' [-Wimplicit-function-declaration] 的隐式声明程序工作,但我如何修复编译器错误

[英]warning: implicit declaration of function ‘strcpy’ [-Wimplicit-function-declaration] the program work but how i fix the compiler error

struct student * createStudent(char studentName[],int studentAge){
struct student * ptr;
ptr= (struct student *)malloc(sizeof(struct student));
strcpy(ptr->name,studentName);
ptr->age=studentAge;
ptr->next=NULL;

return ptr;

}

Compilation result: 60663645638018396.c: In function 'createStudent': 60663645638018396.c:46:5: warning: implicit declaration of function 'strcpy' [-Wimplicit-function-declaration] strcpy(ptr->name,studentName); ^ 60663645638018396.c:46:5:警告:内置 function 'strcpy' 的隐式声明不兼容

该程序正在运行,但我不明白编译错误是什么。

strcpy()在 header string.h中声明。

添加

#include <string.h>

到代码的开头。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM