Thread: C++ database help

  1. #1
    Registered User
    Join Date
    Mar 2004

    C++ database help is my problem. I have to write a program that will ask the user where their database name is. It will then make a system call and check to see if there is a folder with that name, if there isn't..then it will create 2 new (binary format) files called relcat and attrcat.

    Now, each file is a database. Relcat will contain 2 entries...1 about itself and one about attrcat.
    The other is attrcat..which will contain 12 entries...6 of itself and 6 of relcat.

    Now, each will have it's own class with the structures

    relcat( char relname[20], int reclength, int attrcount, int reccount, int sortfield, char format)

    attrcat( int attrnum, int attroffset, int attrlength, char attrtype, char attrname[20], char relname[20])
    looks sorta like that

    Each file will be a fixed length record with those structs as the guidelines. However, I can't figure out how the structs are supposed to help me.
    I just can't figure out how to make the tables dynamic...such as...record count just go up as relcat gains rows, and the attrcat info in relcat should go up as the attrcat table gains info. Soo..rec count in relcat should eventually be 2 and 12 in attrcat.

    I don't see how I'm supposed to get all of that information put in without hardcoding it all so that the format is right.

    Any help is appreciated =/

  2. #2
    Tha 1 Sick RAT
    Join Date
    Dec 2003
    If your problem rests with dynamic allocation of memory then you may want to look at employing the STL's vector class. Other than that I can't try to help ya without looking at something you've done so far.
    And good luck with it. I can't say I fully get what you're trying to explain.
    A hundred Elephants can knock down the walls of a fortress... One diseased rat can kill everyone inside

  3. #3
    Registered User manofsteel972's Avatar
    Join Date
    Mar 2004

    How structs help you when reading binary records.

    If you create a structure of the fixed length records you will have a way to read and write the records to the binary file. You simply load the structure with the data you want to write to the file then write the structure to the file. If you want to read a record from teh file you simply load the structure from the binary file. If you want to look up examples try searching google for "using structures to read binary files" or you can look at this sites
    Last edited by manofsteel972; 03-22-2004 at 06:36 AM.
    "Knowledge is proud that she knows so much; Wisdom is humble that she knows no more."
    -- Cowper

    Operating Systems=Slackware Linux 9.1,Windows 98/Xp
    Compilers=gcc 3.2.3, Visual C++ 6.0, DevC++(Mingw)

    You may teach a person from now until doom's day, but that person will only know what he learns himself.

    Now I know what doesn't work.

    A problem is understood by solving it, not by pondering it.

    For a bit of humor check out xkcd web comic

  4. #4
    Registered User
    Join Date
    Mar 2004


    Thanks guys, I ended up figuring it out a lot of it on my own before I got a reply. Heh, I basically ended up saying "Screw the functions...I'll just do it all in main! I'll practice good design when good design doesn't mean stuff NOT WORKING FOR NO REASON! :mad"

    However, my issue now is with system calls.
    Here's what I need to do.

    I need to do stuff in this order:
    1. Get in a user input for a database name ie: Trip
    2. Make the directory using a system command:
    Sample of my code:
    char dbname[80], systemcall[80];
    strcpy(systemcall, "mkdir ");
    strcat(systemcall, dbname);

    strcpy(systemcall, "cd ")
    strcat(systemcall, dbname);

    Basically copy "mkdir " to system call, then append the name the user typed in to it. That makes the dir fine, then CD into it.

    3. After I make the directory, I have to CD into it and check to see if 2 files are there. IF they are, the database already exists, if they aren't, it isn't so I make a new one.
    (Problem is, I CD into the directory, but it checks for the files in the previous directory like I'd never called system at all.)

    Any advice on how to get around this problem would be appreciated. I have to check for files in the new directory, not the home one.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. literature database: help with planning
    By officedog in forum C++ Programming
    Replies: 1
    Last Post: 01-23-2009, 12:34 PM
  2. Creating a database
    By Shamino in forum Game Programming
    Replies: 19
    Last Post: 06-10-2007, 01:09 PM
  3. Replies: 10
    Last Post: 05-18-2006, 11:23 PM
  4. Developing database management software
    By jdm in forum C++ Programming
    Replies: 4
    Last Post: 06-15-2004, 04:06 PM
  5. Making a Simple Database System
    By Speedy5 in forum C++ Programming
    Replies: 1
    Last Post: 03-14-2003, 10:17 PM