Own lil' "database" ?

This is a discussion on Own lil' "database" ? within the C Programming forums, part of the General Programming Boards category; Hi, I'm looking for some kind of tutorial for writing a tool that does the following: It reads multiple values ...

  1. #1
    Registered User
    Join Date
    Mar 2008
    Posts
    15

    Own lil' "database" ?

    Hi,

    I'm looking for some kind of tutorial for writing a tool that does the following:
    It reads multiple values and compares them to a small database and then reads a string from the database which is assigned to the values.
    So lets say we gather val1, val2 and val3 with the program it would be cool to have a database file with a format like that:
    /* val1, val2, val3, matching string */
    0, 0, 0, "Stringallzero"
    0, 1, 0, "Stringval2is1"
    473, 2, 5, "Yet another string"

    The "," as separator would work for me as I won't have to use them in the strings.
    Can this be done somehow easily and can the performance keep up with a "in-code" database using switch() - which is my current solution:
    Code:
    switch (val 1)
    {
       case 0: switch (val 2)
       {
          [...]
    This is ugly and makes the binaries quite big...and the database can't be altered without re-compiling which is quite annoying, too...

    So if anyone has a piece of code or knows some good tutorial please let me know

    Peter

  2. #2
    Technical Lead QuantumPete's Avatar
    Join Date
    Aug 2007
    Location
    London, UK
    Posts
    894
    can the performance keep up with a "in-code" database using switch
    Nope, opening a file and reading from it, will in most cases (certainly the first time) have to hit the hard drive, which is a slow operation. However, on modern computers you might well not notice a difference if the file isn't several Mb big.

    I assume that when you say database, you actually mean datafile. Have a look at the FAQ for information on how to read from files!

    QuantumPete
    "No-one else has reported this problem, you're either crazy or a liar" - Dogbert Technical Support
    "Have you tried turning it off and on again?" - The IT Crowd

  3. #3
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,442
    Instead of coming up with your own data format and then writing a parser for it, you should consider using SQLite, which is a relational database engine that can easily be embedded into your program.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  4. #4
    Crazy Fool Perspective's Avatar
    Join Date
    Jan 2003
    Location
    Canada
    Posts
    2,640
    I'd recommed berkely DB since you basically just want to map keys to string values. It can be run from disk or embedded as well.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A Lil Help With Inheritance...
    By frassunit in forum C++ Programming
    Replies: 16
    Last Post: 03-04-2009, 02:54 AM
  2. a lil' help using fread()
    By wuzzo87 in forum C Programming
    Replies: 8
    Last Post: 10-06-2007, 03:52 AM
  3. lil prob
    By psycho88 in forum C Programming
    Replies: 7
    Last Post: 12-01-2005, 11:04 AM
  4. a lil help.. prog's done but wrong output
    By gamer4life687 in forum C++ Programming
    Replies: 5
    Last Post: 09-13-2005, 02:32 AM
  5. i need a lil venting.
    By RoD in forum A Brief History of Cprogramming.com
    Replies: 18
    Last Post: 01-03-2003, 09:21 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21