Hi, I've searching for a while to figure out how to get certain information from a file but can't seem to pin point it.
I have a file with this:
001
John Smith
quizes
90
85
95
99
75
80
92
100
50
70
midterm
88
final
85
attendance(out of 20)
14
002
Jane Smith
quizes
90
85
95
99
75
80
92
100
50
70
midterm
88
final
85
attendance(out of 20)
14
ect..
I'm trying to get the user to input the students name then show the scores that are in the file for that particular student.
Any help on what to do. Or if there is a specific name for this so that i can search it would be great.
Also, Having the .txt file set up like is ok right?
001 and 002 are the id numbers for the students.
Thanks
Getting info from file
Page 1 of 16 Replies - 267 Views - Last Post: 25 July 2010 - 06:55 PM
Replies To: Getting info from file
#3
Re: Getting info from file
Posted 25 July 2010 - 06:47 PM
Yes, i know how to do this. the problem which i should have mentioned, is when i ask the user for a students name i want it to only displays that section of the file. from the idnum to attendance.
This post has been edited by AbeB: 25 July 2010 - 06:47 PM
#4
Re: Getting info from file
Posted 25 July 2010 - 06:50 PM
So parse the file appropriately. Read each line, and when you discover that student's name on a certain line matches what the user requested, you know that all the grades that follow should be shown.
#5
Re: Getting info from file
Posted 25 July 2010 - 06:52 PM
I see. and i use to make it stop once it ends with that particular students information?
#6
Re: Getting info from file
Posted 25 July 2010 - 06:54 PM
That's what you said you wanted.
#7
Re: Getting info from file
Posted 25 July 2010 - 06:55 PM
one way that might prove a little easier, if your text file format can be changed is to consolidate the data onto the same line, example
001 Jane Doe
Quizzes 00 00 00 00 00
Exams 00 00
Midterm 00
Final 00
Attendance 14
002 John Doe
Quizzes 00 00 00 00 00
Exams 00 00
Midterm 00
Final 00
Attendance 14
This way you can create a loop in which you know that each student only consist of 6 lines to be read. Then you just check every 7th line to find the student. Once the student is found then you can process the rest of their data.
001 Jane Doe
Quizzes 00 00 00 00 00
Exams 00 00
Midterm 00
Final 00
Attendance 14
002 John Doe
Quizzes 00 00 00 00 00
Exams 00 00
Midterm 00
Final 00
Attendance 14
This way you can create a loop in which you know that each student only consist of 6 lines to be read. Then you just check every 7th line to find the student. Once the student is found then you can process the rest of their data.
This post has been edited by Nakor: 25 July 2010 - 07:01 PM
Page 1 of 1
|
|

New Topic/Question
Reply




MultiQuote




|