My problem is very simple, but I really don't know how to manipulate strings in C
The problem is: I have a struct called person
struct person
{
char name[25] // use char *name better?
}p;
I also have a function called p *addNewPerson(char *name)
p *addNewPerson(char *name)
{
p *newPerson = (p *)malloc(sizeof(person));
//here how can I assign the name to this new person?
...
return newPerson;
}
So, in the main function
void main()
{
for(; ;)
{
char input[25];
scanf("%s", input); // is this way possible?
//shoud I do something with this "input", like input[strlen(input)-1] = '\0'
//call addNewPerson()
p *newPerson = addNewPerson(&input);
//store this newPerson in some data structure
...
}
}
Clarification: the question is how can I assign the name to this new person inside p *addNewPerson(char *name)
?