Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   How do I get certain part of a file? (http://www.go4expert.com/forums/i-part-file-t16263/)

Lokantis 19Feb2009 07:13

How do I get certain part of a file?
I am using C.
Say I have a FILE datatype studentRecord in the following format " EntryIndex. lastname, firstname: score" for example "12. Simpson, Homer: 15". That is one record. Records are separated by space. Suppose the user enters number 12, how do I print out that exact record number 12? Logically I would think do somehing like
go through the file character by character, if find combination like "studentNumber + "."" print out characters starting from that point until a third space character.

shabbir 19Feb2009 09:04

Re: How do I get certain part of a file?
Read the complete file into some structure which is equivalent to the data in the file and then either arrange them in a Linked List or even array and then traversing through it would help you get the needed record.

The above solution would work assume you have few records and not thousands of them or else you may run out of memory

All times are GMT +5.5. The time now is 06:57.