6 Replies - 267 Views - Last Post: 25 July 2010 - 06:55 PM Rate Topic: ***** 1 Votes

#1 AbeB  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 97
  • Joined: 28-February 10

Getting info from file

Posted 25 July 2010 - 06:39 PM

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

Is This A Good Question/Topic? 0
  • +

Replies To: Getting info from file

#2 Nakor  Icon User is offline

  • Professional Lurker
  • member icon

Reputation: 431
  • View blog
  • Posts: 1,452
  • Joined: 28-April 09

Re: Getting info from file

Posted 25 July 2010 - 06:44 PM

you'll want to look into File input and output, or just File I/O.

Here's a link to get you started File I/O
Was This Post Helpful? 0
  • +
  • -

#3 AbeB  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 97
  • Joined: 28-February 10

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

Was This Post Helpful? 0
  • +
  • -

#4 Oler1s  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1394
  • View blog
  • Posts: 3,884
  • Joined: 04-June 09

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.
Was This Post Helpful? 0
  • +
  • -

#5 AbeB  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 97
  • Joined: 28-February 10

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?
Was This Post Helpful? 0
  • +
  • -

#6 Oler1s  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1394
  • View blog
  • Posts: 3,884
  • Joined: 04-June 09

Re: Getting info from file

Posted 25 July 2010 - 06:54 PM

That's what you said you wanted.
Was This Post Helpful? 0
  • +
  • -

#7 Nakor  Icon User is offline

  • Professional Lurker
  • member icon

Reputation: 431
  • View blog
  • Posts: 1,452
  • Joined: 28-April 09

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.

This post has been edited by Nakor: 25 July 2010 - 07:01 PM

Was This Post Helpful? 1
  • +
  • -

Page 1 of 1