Thread: Saving?!

  1. #1
    Registered User
    Join Date
    Dec 2003
    Posts
    9

    Saving?!

    Hello,

    I know this may sound like a stupid question but i cant figure out how to make a database(?) What i am tring to do is make a program to keep track of my clients.... So i figrued that i would just wright all the clients into a txt file.... that works.. but i cant figure out how to edit the entries from the text file... the i thought i was doing it wrong.... so far all i have figured out is that using a .txt file to save work from a program is not how you go about it. if any one could tell me what i am suposed to do or a place to find it please tell me.

    thanks,
    KJ

  2. #2
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787
    a .txt file would be fine to do what you want... I would load the entire file into memory, then edit what you need while it's still in memory. then dump the memory into the file using ios::trunc.
    Join is in our Unofficial Cprog IRC channel
    Server: irc.phoenixradio.org
    Channel: #Tech


    Team Cprog Folding@Home: Team #43476
    Download it Here
    Detailed Stats Here
    More Detailed Stats
    52 Members so far, are YOU a member?
    Current team score: 1223226 (ranked 374 of 45152)

    The CBoard team is doing better than 99.16% of the other teams
    Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)

    Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT

  3. #3
    Registered User
    Join Date
    Dec 2003
    Posts
    9
    Yes, but what i was going for was like an address book, and it lets you add more people. However it should let you slect one to view it in more detail(money they owe, venue, performnces, ect..). Hence the reason why .txt files wont work... or maybe they will, but what i am tring to say is that if use .txt files i'm going to end up with about 30 of them... I'm just looking for a better way to solve the problem...

    Thanks,
    KJ

  4. #4
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >i cant figure out how to make a database(?)
    For a simple database you can use a single file (or several files that you choose from based on a search key) to hold the records, then read them into a suitable data structure in memory. Any changes made to the database would be done in memory, then written back to the file to save them. For a larger and more professional database, you're looking at writing an external data structure such as some variant of a B-tree to give you efficient lookup and modification without having to read every record into memory. However, I wouldn't recommend that particular path unless it is absolutely necessary, external B-trees are not trivial to write.
    My best code is written with the delete key.

  5. #5
    Registered User
    Join Date
    Dec 2003
    Posts
    9
    Ok, i dont think you get what i am asking... What i am tring to do is write to a file then pull up only part of it hers an example
    Stuff a
    blaw bla blaw

    stuff b
    blaw blaw
    blaw
    blawww

    stuff C
    blaw blaw blaw blaw
    blaw

    and so on... so what i want to be able to do is pick a spot in a file and only read that block.... not sure if it is possible tough because i tired everything.

    -KJ
    Last edited by kjmagic; 12-19-2003 at 09:26 AM.

  6. #6
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >i dont think you get what i am asking...
    I'm well aware of what you want to do. However, I'm also pretty sure you don't want to do what you think you do.

    >so what i want to be able to do is pick a spot in a file and only read that block....
    This is simple provided you use binary files and have a strict indexing scheme as well as records that will never vary in size. For most applications, this is too restrictive, so we usually recommend processing whole files instead of individual records.
    My best code is written with the delete key.

  7. #7
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787
    >>so what i want to be able to do is pick a spot in a file and only read that block.... not sure if it is possible tough because i tired everything.

    if all you want to do is read, I suggest using an XML file... it looks prettier, but it's a little more code to parse the XML file than just search for a name in a list... you could set it (txt file) up this way:

    Code:
    NAME
    (XXX)XXX-XXXX
    ADDRESS
    ADDRESS
    ADDRESS
    
    NAME
    (XXX)XXX-XXXX
    ADDRESS
    ADDRESS
    ADDRESS
    and an XML file would look something like:
    Code:
    <PROGRAM NAME>
       <BLOCK>
          <NAME>name</NAME>
          <PHONE>(XXX)XXX-XXXX</PHONE>
          <ADDY1>address</ADDY1>
          <ADDY2>address</ADDY2>
          <ADDY3>address</ADDY3>
       <BLOCK>
    and then search for the name and only load the next four lines... that works good for one search per run of the program and no inserting... if you're planning on having it search the file multiple times, it's easier to put the file in a linked list or even an array of structs... either way, if you want to insert something in a specific place, it's much easier to go with an array of structs or linked list...
    Last edited by major_small; 12-19-2003 at 11:33 AM.
    Join is in our Unofficial Cprog IRC channel
    Server: irc.phoenixradio.org
    Channel: #Tech


    Team Cprog Folding@Home: Team #43476
    Download it Here
    Detailed Stats Here
    More Detailed Stats
    52 Members so far, are YOU a member?
    Current team score: 1223226 (ranked 374 of 45152)

    The CBoard team is doing better than 99.16% of the other teams
    Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)

    Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. New to C++ problem saving files
    By wesm in forum C++ Programming
    Replies: 2
    Last Post: 11-02-2005, 02:00 PM
  2. Replies: 2
    Last Post: 06-16-2005, 10:03 AM
  3. saving a binary tree??
    By fayte in forum C++ Programming
    Replies: 9
    Last Post: 01-27-2005, 01:32 PM
  4. Saving vectors of structures problem
    By redeck in forum C++ Programming
    Replies: 4
    Last Post: 12-09-2004, 04:47 PM
  5. File saving problem in DevC++ pls help ???
    By intruder in forum C Programming
    Replies: 3
    Last Post: 12-17-2002, 01:17 AM