Thread: Databasee.....

  1. #1
    Senor Member nomi's Avatar
    Join Date
    Jan 2004
    Posts
    129

    Finally Databased....

    After a lot of help from members of this board and a lot of time consuming coding I finally believe I have everything working in my database according to my planning....

    >How its coded and are my programming techniques messed up?
    I dont know, thats why you guys are here, to mock, insult and correct me....and thats exactly what I want you guys to do.

    This is my rough copy without any of the commenting that I will put intomorrow. I have put in just what the function is supposed to do with my prtoypes...

    I would like you guys to do the aforementioned things and tell me where I have gone wrong with my code and ways in which I could improve on my code without, and I mean without, making any drastic changes...coz frankly, I dont have the time to redo my code from a different perpective....

    Just coz i know there may be compiling problems, I am aattaching the *.exe. Theres also a file called 'WMinventory.dat', which is my data basically....

    I know some of the functions, such as searchItems dont search all that well so i would like you guys to tell me how to improve it.

    Attached Files:

    database(FINALrough).cpp
    database(FINALrough).exe
    WMinventory.dat

    Thank you for any help in advance.

    All your inputs are important to me... ....lolz j/k about the grins...

    EDIT: NOTE: This is my first attempt at a database so i really have no idea of advance level programming. All I know in C is in that puny little file....

    EDITagain: That took some time to type....

    EDITagain 'n again.
    Last edited by nomi; 01-13-2004 at 08:59 PM.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,665
    Looking pretty good for a first attempt

    Some points for you to ponder
    1. Name your source file to be database(FINALrough).c
    You're actually compiling this using a C++ compiler. Whilst this doesn't matter much, it's all too easy to slip in some C++ feature without realising it. Only much later do you find out that what you thought was C is being rejected by a real C compiler.

    2. void searchItems(structure [],int);
    Put the variable names into the prototype, like so
    void searchItems(structure inventory[],int arrayL);
    It helps to document the prototype, and is especially useful when you start to create libraries with separate header files.

    3. gets(test);
    Very bad - see the FAQ
    Never use gets() for anything, its far too unsafe, so its best to never get into the habit of using it
    fgets( test, sizeof test, stdin );
    is almost the same except
    - it is safe in that it will not overflow your buffer
    - it stores a newline (\n), which you may need to remove

    4. while(!feof(dataFile))
    This is the feof() "bug", which is also in the FAQ
    In this case, the correct loop would be
    while ( fgets(inventory[i].name, MAXchar,dataFile) != NULL )
    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
    Senor Member nomi's Avatar
    Join Date
    Jan 2004
    Posts
    129
    Hmmm....

    Thx...I'm going to make some changes....specially documentation...but,

    >while ( fgets(inventory[i].name, MAXchar,dataFile) != NULL )
    this crashes my program for some reason...

    I'm going to change the fgets....but i have a question....doesnt' gets keep the '\n' character too?

  4. #4
    Senor Member nomi's Avatar
    Join Date
    Jan 2004
    Posts
    129
    Is this technique good to take out the '\n'?

    inventory[i].name[strlen(inventory[i].name)-1]='\0';

  5. #5
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    >Is this technique good to take out the '\n'?
    >inventory[i].name[strlen(inventory[i].name)-1]='\0';

    No. (It may not be there.)
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  6. #6
    Been here, done that.
    Join Date
    May 2003
    Posts
    1,164
    Originally posted by nomi
    Hmmm....

    Thx...I'm going to make some changes....specially documentation...but,

    >while ( fgets(inventory[i].name, MAXchar,dataFile) != NULL )
    this crashes my program for some reason...

    I'm going to change the fgets....but i have a question....doesnt' gets keep the '\n' character too?
    No, gets() does not keep the '\n'. It relies on it being there. So if there isn't one it will happily read until it hits the crash point.

    fgets() reads until '\n' or buffer full.
    Definition: Politics -- Latin, from
    poly meaning many and
    tics meaning blood sucking parasites
    -- Tom Smothers

  7. #7
    Senor Member nomi's Avatar
    Join Date
    Jan 2004
    Posts
    129
    What I have been trying for some time is to crash my programme....

    Heres an updated copy, please try to crash it and tell me how you did it sso i can fix it....

    ATtched is the latest *.exe

  8. #8
    Senor Member nomi's Avatar
    Join Date
    Jan 2004
    Posts
    129
    >Name your source file to be database(FINALrough).c

    When I try that....I get the following error:

    "
    C:\Dev-Cpp\lib/libconio.a(conio.o.b)(.eh_frame+0x11):conio.c: undefined reference to `__gxx_personality_v0'

    Execution terminated
    "

    Why is that....?

    EDIT: AWW MAN.....every time I go into view Items i see another line added to the end of the data.....
    Last edited by nomi; 01-14-2004 at 03:44 PM.

  9. #9
    Senor Member nomi's Avatar
    Join Date
    Jan 2004
    Posts
    129
    The source code:

  10. #10
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,665
    > C:\Dev-Cpp\lib/libconio.a(conio.o.b)(.eh_frame+0x11):conio.c: undefined reference to `__gxx_personality_v0'
    Remove the object file and try again
    It's confused by the switch from C++ to C, and there's a bit of C++ left over
    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.

  11. #11
    Senor Member nomi's Avatar
    Join Date
    Jan 2004
    Posts
    129
    you want me to remove conio??
    but i needd it...

  12. #12
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,665
    > Remove the object file and try again
    No, I meant remove database.o and re-create it by compiling it again
    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.

Popular pages Recent additions subscribe to a feed