I have a struct storing persons' names, surnames and salaries, but the number of their names is random. For example:
list.txt
John Smith Green 1000 //He has two names Jennifer Wilson 2000 //She has one name Steve Adams 1500 //He has one name James Robert Harris 1250 //He has two names Robin Walker 1750 //He has one name
I want to store their names in person[count].name
, their surnames in person[count].surname
and their salaries in person[count].salary
.
To do that, I wrote:
fscanf(file, "%s %s %d", person[count].name, person[count].surname, &person[count].salary)
However, problem is that if a person has two names, his second name is stored in person[count].surname
, and I cannot take the surname.
How can I take the name of a person with two names in person[count].name
?
For this text file:
person[0].name ==> "John Smith"
person[1].name ==> "Jennifer"
person[2].name ==> "Steve"
person[3].name ==> "James Robert"
person[4].name ==> "Robin"