Solved

Source Code Needed

Posted on 1997-04-06
2
212 Views
Last Modified: 2010-04-15
I am writing a Home Inventory Program and am in over my head.  I am looking for source code, not to copy but to get ideas from.....
0
Comment
Question by:greedyfly
2 Comments
 

Accepted Solution

by:
reyelts earned 50 total points
ID: 1249828
 For what platform? In any event, it would probably be best to
write this sort of program in C++ ( it seems to lend itself to
that ). If however you don't know C++ you can simulate
object-orientedness using C, just with typedefs.

  If an item/object is the base of the model than you can do something like this...

  /* The condition of an item */
  typedef _ItemCondition enum {
    NEW,
    USED,
    WORTHLESS,
    BORROWED,
    LOANED_OUT
  } ItemCondition;
 
  /* The return status from a function call */
  typedef _ReturnStatus _enum {
    SUCCESS,
    GENERAL_FAILURE,
    BAD_ARGUMENT,
    INSUFFICIENT_MEMORY,
    INSUFFICIENT_DISK
  } ReturnStatus;
   
  /* An item */    
  typedef struct _ITEM {
    char            *sName;   /* The name of the item       */
    char            *sBrand;  /* The brand of the item      */
    ItemCondition   Condition;
    etc...
   
    struct _ITEM*   NextItem;
    struct _ITEM*   PreviousItem;

  } ITEM, *PITEM;

  Then you need something like the following functions.
  /* Create a new item */
  ReturnStatus NewItem( PITEM pNewItemStats );

  /* Remove an existing item */
  ReturnStatus RemoveItem( int iItemIndex );

  /* Change an item's settings */
  ReturnStatus SetItem( PITEM pItemStats, int iItemMask );

  /* Save all the items to disk */
  ReturnStatus SaveItems( PITEM pItemList );
 
  /* Load all of the items from disk */
  PITEM LoadItems();

  /* Free all of the items and resources allocated */
  ReturnStatus FreeItems( PITEM pItemList );
 
  So finally, your program looks something like...

  int main( int argc, char** argv ) {

    PITEM pItemList;  /* Pointer to the list of items */

    HandleArgs( argc, argv ); /* Deal with passed arguments */

    pItemList = LoadItems(); /* Load all of the items into mem */

    DoWhateverElseYouNeedTo();

    FreeItems( pItemList );

    return( EXIT_SUCCESS );
}
   
0
 

Author Comment

by:greedyfly
ID: 1249829
I am only able to work in C right now.  This will help.  Thank you very much...
-greedyfly
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
The goal of this video is to provide viewers with basic examples to understand and use structures in the C programming language.
The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question