You cannot assign to an array like that. Use strcpy instead.
strcpy(final.name, p[i].name);
Remember to include string.h
.
Pregunta
I'm building a program that takes in names of users along with there Date of Birth and prints out the youngest user. I'm using two structs to do this:
struct date
{ int day;
int month;
int year;
};
struct person
{ char name[80];
struct date birth;
};
And two variables:
struct person p[5], final;
The users are put into Variable p. Then I for loop putting the first user data into final then comparing everyone else with final. What should be left in final is the data if the youngest user which I print out.
However, when I try to put the name of p into final I get this compiler error:
error: incompatible types when assigning to type ‘char[80]’ from type ‘char *’
final.name = p[i].name;
Can someone help me please!
Thanks!!!
edit:
I copy the data over like this (sorry for missing this out earlier):
final.name = p[i].name;
final.birth.day = p[i].birth.day;
final.birth.month = p[i].birth.month;
final.birth.year = p[i].birth.year;
Solución
You cannot assign to an array like that. Use strcpy instead.
strcpy(final.name, p[i].name);
Remember to include string.h
.