Problem with two set of functions..

This is a discussion on Problem with two set of functions.. within the C Programming forums, part of the General Programming Boards category; I have designed a set of functions to handle structured table in a file. You can say a small DBMS. ...

  1. #1
    Registered User zahid's Avatar
    Join Date
    Aug 2001
    Posts
    532

    Problem with two set of functions..

    I have designed a set of functions to handle structured table in a file. You can say a small DBMS. It has quick search, addrecord, delete record, modify record concurrency control and recovery features.

    I just have to change the structure and
    read_record()
    write_record()
    ......................
    and few other functions.

    Now the problem is, I need to work with two table (structure) / DB at a time. It's working saperately..

    Global variables, typedef struct PINFO RECORD are giving problem.

    Any one have suggestion?.. least effort to continue.
    [ Never code before desk work ]
    -------------------------------------:-->
    A man who fears Nothing is the man who Loves Nothing
    If you Love Nothing, what joy is there in your life.
    =------------------------------------------------------= - I may be wrong.

  2. #2
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    >>Any one have suggestion?..
    Nothing definate without better understanding how your code works, but here are some thoughts:

    - Using two files - use two FILE* variables
    - Using two structures - make an array or list of stuctures. Maybe have two link lists?

    >Global variables
    Try to avoid them where possible. Create your variables locally, and pass them as function parameters.

    >typedef struct PINFO RECORD
    Why is this giving you a problem?
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  3. #3
    Registered User zahid's Avatar
    Join Date
    Aug 2001
    Posts
    532
    >typedef struct PINFO RECORD
    Why is this giving you a problem?
    Ohh.... RECORD is the struct used in all other functions.
    [ Never code before desk work ]
    -------------------------------------:-->
    A man who fears Nothing is the man who Loves Nothing
    If you Love Nothing, what joy is there in your life.
    =------------------------------------------------------= - I may be wrong.

  4. #4
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    >>RECORD is the struct used in all other functions.
    Well, according to what you showed me, it isn't an actual structure, it's a typedef for one:
    >typedef struct PINFO RECORD

    So, again, why does it cause you a problem?
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  5. #5
    Registered User zahid's Avatar
    Join Date
    Aug 2001
    Posts
    532
    Okay...

    SET1:
    Code:
    file: def.h
    #define FILE_NAME  "file.db"
    #define INDEX_FILE  "file.dx"
    
    struct PINFO{
    char     string[33];
    int        number;
    }
    
    typedef struct PINFO RECORD;
    
    file: function.h
    
    int fun_a(RECORD *db)
    {
    
    }
    
    
    RECORD * fun_b()
    {
    
    }
    
    
    file: fun_pinfo.h
    
    int writerecord(char *fname)
    {
    
    }
    
    int readrecord(char *fname)
    {
    
    }
    
    int displayrecord(RECORD *db)
    {
    
    
    }

    SET2:
    Code:
    file: def2.h
    
    #define FILE_NAME  "file2.db"
    #define INDEX_FILE  "file2.dx"
    
    struct DEMO{
    int        number;
    int        status;
    char     name[33];
    }
    
    typedef struct DEMO RECORD;
    
    
    file: function2.h
    
    int fun_a(RECORD *db)
    {
    
    }
    
    
    RECORD * fun_b()
    {
    
    }
    
    
    
    file: fun_demo
    
    int writerecord(char *fname)
    {
    
    }
    
    int readrecord(char *fname)
    {
    
    }
    
    int displayrecord(RECORD *db)
    {
    
    
    }

    Now how can I use this code?
    It works separately with few modifications in func_*h, def*.h only.


    Except system("");
    How can I use this two set in the same application.
    Last edited by zahid; 12-04-2002 at 07:32 AM.
    [ Never code before desk work ]
    -------------------------------------:-->
    A man who fears Nothing is the man who Loves Nothing
    If you Love Nothing, what joy is there in your life.
    =------------------------------------------------------= - I may be wrong.

  6. #6
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    >typedef struct PINFO RECORD;
    >typedef struct DEMO RECORD;
    Two typedefs to the same name? Why not change them to be unique?
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  7. #7
    Registered User zahid's Avatar
    Join Date
    Aug 2001
    Posts
    532
    Then I canot use common functions for the application. I have to change all of them.
    [ Never code before desk work ]
    -------------------------------------:-->
    A man who fears Nothing is the man who Loves Nothing
    If you Love Nothing, what joy is there in your life.
    =------------------------------------------------------= - I may be wrong.

  8. #8
    Registered User zahid's Avatar
    Join Date
    Aug 2001
    Posts
    532
    Actually.... I want to a method to make both as unique.
    There could be two saperate functions through which the application will work, pass record as parameter. Such as two object. Just if any brilliant idea. Actually I missed it (that I have to work with two unit in a single app. and they will make problem) before I code.

    You know I can make it work through system("");
    [ Never code before desk work ]
    -------------------------------------:-->
    A man who fears Nothing is the man who Loves Nothing
    If you Love Nothing, what joy is there in your life.
    =------------------------------------------------------= - I may be wrong.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. The new FAQ
    By Hammer in forum A Brief History of Cprogramming.com
    Replies: 34
    Last Post: 08-30-2006, 10:05 AM
  2. OpenGL Window
    By Morgul in forum Game Programming
    Replies: 1
    Last Post: 05-15-2005, 12:34 PM
  3. Basic Math Problem. Undefined Math Functions
    By gsoft in forum C Programming
    Replies: 1
    Last Post: 12-28-2004, 02:14 AM
  4. Problem displaying (structs functions)
    By dayknight in forum C++ Programming
    Replies: 7
    Last Post: 02-22-2004, 05:11 PM
  5. Major Problem
    By Unregistered in forum C++ Programming
    Replies: 3
    Last Post: 02-19-2002, 12:06 PM

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