Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial

Reiad Khan
214 PointsC: Please help! strcpy error
I'm new to programming. I was just fooling around with some code trying to understand how typedef struct works. I used the strcpy function in the code below, because before in my makePerson function i was using the statement person.name=f which returned an error (which I later learnt was because arrays are not assignable in C).
Now I am using the code below, which compiles and runs, but now I'm getting the error flagged in xcode at my first strcpy statement which reads: "Implicitly declaring library function 'strcpy' with type 'char (char, const char *)' "
Can someone please explain what is going on and how I can fix it?
#include <stdio.h>
typedef struct {
char name[20];
char lastname[20];
}Person;
Person makePerson(char *f, char *s);
int main(){
Person Reiad;
Reiad = makePerson("Reiad","Khan");
printf("name: %s %s\n",Reiad.name, Reiad.lastname);
return 0;
}
Person makePerson(char *f, char *s){
Person person;
strcpy(person.name,f);
strcpy(person.lastname,s);
return person;
}
2 Answers
Konstantinos Kadoglou
6,057 PointsYou forgot to import the function which includes strcpy. Add : #include<string.h>

Reiad Khan
214 PointsThank you! I added #include <string.h> and that solved the issue.