Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c

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: warning: incompatible implicit declaration of built-in function ‘strcpy’

the program is working but i dont understand what is the compile error.

like image 264
maorben241 Avatar asked Jul 13 '26 17:07

maorben241


1 Answers

strcpy() is declared in the header string.h.

Add

#include <string.h>

to the beginning of your code.

like image 155
MikeCAT Avatar answered Jul 16 '26 09:07

MikeCAT