+ 1

PLEASE HELP. Storing data from text file into array of structures *****SOLVED*****

Hello. Any help would be greatly appreciated. I an trying to store each line of text in a text file into array of structures, so that I can sort the data later on but it is not working. Here is an example of how the text file is layed out. Web Developer // JobTitle 7 // NumSkills PHP // Skills v HTML CSS Javascript jQuery JSON SQL 60000 // Salary Knox County Government // Company I want to store Web Developer into an array of jobs.jobTitle the next line I would like to store into jobs.NumSkills, and then I would like to loop depending on what is it NumSkills. and store that information into jobs.Skills, once the loop is finished I would like to store the next line into Salary, the next into Company. It is not working as JobTitle holds more than it should. Here is what I have for my loop. while (!in_stream.eof() && (count < MAX_LENGTH)){ in_stream.getline(jobs[count].jobTitle, MAX_LENGTH, '\0'); in_stream >> jobs[count].numSkills; for(int i = 0; i < jobs[count].numSkills; i++){ in_stream >> jobs[count].skills[i]; } in_stream >> jobs[count].salary; in_stream >> jobs[count].company; ++count; } I have got the whole code posted on Code Playground. https://code.sololearn.com/cGd0l3g25coL

27th Jan 2020, 5:20 PM
Baydud
Baydud - avatar
19 Antworten
+ 3
@~ swim ~ Thank you!!! I added a for loop to loop through depending how many skills were listed, in the example 7. and then stop after it reaches the numSkills and continue to read the salary and company, then start back at jobTitle, and quitting at EOF.
27th Jan 2020, 9:32 PM
Baydud
Baydud - avatar
+ 2
thank you so so much. i will work on it
28th Jan 2020, 12:58 PM
Baydud
Baydud - avatar
+ 1
this has been solved. I’ll post the finished code so you can see it. It doesn’t run well on sololearn due to multiple prompts
31st Jan 2020, 7:29 PM
Baydud
Baydud - avatar
+ 1
It took a while but it is much more rewarding this way and I learn more.
31st Jan 2020, 7:31 PM
Baydud
Baydud - avatar
0
@blackwinter What exactly do you mean?
27th Jan 2020, 8:22 PM
Baydud
Baydud - avatar
0
if anyone can help, my program is printing out only one job title when i have many, and is printing out memory addresses for the skills. the count also never stops. I changed the eof read out to what you suggested
28th Jan 2020, 7:35 AM
Baydud
Baydud - avatar
0
Will do one sec, thank you so much
28th Jan 2020, 7:44 AM
Baydud
Baydud - avatar
0
code.sololearn.com/cGd0l3g25coL/#cpp
28th Jan 2020, 7:51 AM
Baydud
Baydud - avatar
0
I’ll show you what i’ve got so far.
28th Jan 2020, 11:18 PM
Baydud
Baydud - avatar
0
https://code.sololearn.com/cGd0l3g25coL/#cpp If you wanna see. Still have to add some error checking.
1st Feb 2020, 12:52 AM
Baydud
Baydud - avatar