簡體   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