Thread: variables

  1. #1
    Registered User
    Join Date
    Apr 2003


    If I have a database and I dont know how many entries I am going to have is there a way to set it up where it wont matter how many entries i have? Sorry if i didnt explain it right. Also is a way where i start up a program enter some info and then i am able to exit that program and when i start it back up it will remember where i left off? thx for any help.


  2. #2
    Confused Magos's Avatar
    Join Date
    Sep 2001
    For your first question a linked list would probably be the best. As for the second question, store the data in a file. Use file streams for that (ifstream/ofstream).

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  3. #3
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    >For your first question a linked list would probably be the best.
    Actually, it depends more on how lookup would be handled. Lists can only be searched sequentially and databases that have a large number of records implemented as a list can get slow. I would go with a dynamically sized hash table or balanced binary tree/skip list if I had to write a database in C++.
    My best code is written with the delete key.

  4. #4
    Registered User major_small's Avatar
    Join Date
    May 2003
    actually, you might not need anything like that... it depends on what you want to do with it... for example, if you want to do an average with numbers, just put it in a loop...

    another method is just to add something at the end of the data file... then search through it until you find that last item(number) and then search the file again until you get to that line number...
    Join is in our Unofficial Cprog IRC channel
    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

  5. #5
    Me -=SoKrA=-'s Avatar
    Join Date
    Oct 2002
    The way I read it, the answer to the first question would be dinamic memory allocation. The answer to the second, yes, it would be a file with the program settings.
    SoKrA-BTS "Judge not the program I made, but the one I've yet to code"
    I say what I say, I mean what I mean.
    IDE: emacs + make + gcc and proud of it.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. basic question about global variables
    By radeberger in forum C++ Programming
    Replies: 0
    Last Post: 04-06-2009, 12:54 AM
  2. Replies: 15
    Last Post: 09-30-2008, 02:12 AM
  3. esbo's data sharing example
    By esbo in forum C Programming
    Replies: 49
    Last Post: 01-08-2008, 11:07 PM
  4. Replies: 6
    Last Post: 01-02-2004, 01:01 PM
  5. functions to return 2 variables?
    By tim in forum C Programming
    Replies: 5
    Last Post: 02-18-2002, 02:39 PM