Thread: file system

  1. #1
    Registered User
    Join Date
    Oct 2003
    Posts
    55

    file system

    if i write some data on file ... let say student.dat ....
    when i retrieve the data ... it will retrive everything at the same time ... how am i suppose to modify it so that it can search for the information i need only ?

    for example .... in my student.dat contains

    1 Amy IT
    2 Kim Engineering
    3 Pete Management

    when i retrive the data, it will retrive everything ...

    how am i suppose to modidy the codes so that it will display onli ... for example .. information about Kim ony ?

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Well you either

    - read one record at a time, then use say strcmp() on the appropriate field to determine if its the record you're looking for.

    - read the whole file into an array, then use a for loop to step through the array, then use say strcmp() on the appropriate field to determine if its the array element you're looking for.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Oct 2003
    Posts
    55
    what about those function like ...
    Code:
    seekg()
    seekp()
    tellg()
    tellp()
    at what purpose do they serve ?

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    If your records are all the same size, then you can do things like

    seek( record_num * sizeof(record) );

    To access an individual record without having to read all the records before it
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  5. #5
    Registered User
    Join Date
    Oct 2003
    Posts
    55
    Code:
    seek( record_num * sizeof(record) );
    mind explaining to me how to use it ... the syntax looks so blur to me ... sorry if i am annoying but i am still new to C++ ...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. gcc link external library
    By spank in forum C Programming
    Replies: 6
    Last Post: 08-08-2007, 03:44 PM
  2. Inventory records
    By jsbeckton in forum C Programming
    Replies: 23
    Last Post: 06-28-2007, 04:14 AM
  3. Simple File encryption
    By caroundw5h in forum C Programming
    Replies: 2
    Last Post: 10-13-2004, 10:51 PM
  4. Replies: 4
    Last Post: 10-21-2003, 04:28 PM
  5. System
    By drdroid in forum C++ Programming
    Replies: 3
    Last Post: 06-28-2002, 10:12 PM