Thread: I Need Help Writing A Program Using An Array Of Pointers!

  1. #1
    Registered User
    Join Date
    Nov 2002
    Posts
    1

    Unhappy I Need Help Writing A Program Using An Array Of Pointers!

    I need to write an inventory program to maintain a lost of DVD movies by using an array of pointers. Each pointer points to a character array storing a movie title of up to 30 characters.

    The program should:

    Output the list of movies

    Delete a title from the list by entering command
    d
    n (n indicates which title to delete)

    ex: d 3 will delete the third title

    Output the final list

    Any help would be appreciated. Thanks

    [email protected]

  2. #2
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    So... what type of list are you going to use (or are capable of using)? An array, a link list, a tree .....

    I suggest you research them, and decide on one to use.

    Also, if it's an inventory, you'll probably want to use structs too.
    Code:
    #define TOTAL_BOOKS 1000
    
    struct item
    {
       int NumberInStock;
       char Name[100];
       char Author[50];
    };
    
    struct item ItemArray[TOTAL_BOOKS];
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  3. #3
    Registered User
    Join Date
    Nov 2002
    Posts
    36

    Lightbulb #define

    Originally posted by Hammer
    So... what type of list are you going to use (or are capable of using)? An array, a link list, a tree .....

    I suggest you research them, and decide on one to use.

    Also, if it's an inventory, you'll probably want to use structs too.
    Code:
    #define TOTAL_BOOKS 1000
    
    struct item
    {
       int NumberInStock;
       char Name[100];
       char Author[50];
    };
    
    struct item ItemArray[TOTAL_BOOKS];
    Hi Hammer!
    #define.... is it like const???
    Could you please explain little more about it or suggest me to look any reference you know???

  4. #4
    Registered User
    Join Date
    Nov 2002
    Posts
    491
    The short and easy to understand explination of #define is this:

    a variabelt hat is #defined can be of any type and it is a constant throughout yoru program. that is to say, if you do #define MYASS "BIG"

    You CANNOT do MYASS[1] = '2'; somewher ein your program.

    A value that is defined is not accessed like a regular variable, the value of the the #define'd object is basically 'pasted' wherever you put it by the compiler. So

    printf("%s", MYASS);
    is replaced by your compiler with
    printf("%s", "BIG");

    That is the quick and dirty explination, #define's can get very complex and sometimes gross.

  5. #5
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    #define is used to, oddly enough, define something. This is a preprocessor directive. That is to say, before the code is compiled, the compiler goes looking for all of the "#define" stuff. When it comes across it, it does a "search and replace" to fill in the appropriate text.

    Example:

    #define cat dog

    Anywhere you use cat in your program, outside of a string, the preprocessor will replace that text with dog.

    Like so:
    Code:
    #define cat dog
    int main( void )
    {
        int cat;
        cat = 1;
    
        return 0;
    }
    The end result is that 'cat' is replaced with the word 'dog'.

    Now here this isn't very handy. We could do this however:

    #define SIZE 10

    And now we can make an array:

    char myarray[SIZE];
    char int[SIZE];

    So it does have its uses...

    Quzah.
    Hope is the first step on the road to disappointment.

  6. #6
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Originally posted by orbitz
    #define MYASS "BIG"

    You CANNOT do MYASS[1] = '2'; somewher ein your program.
    You can't with the example you have provided, but we could do:

    #define ALPHA bravo

    int ALPHA;
    ALPHA = 10;

    It all depends on how you use it. You used it to define a string, I used it to define a variable name.

    Quzah.
    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Program Plan
    By Programmer_P in forum C++ Programming
    Replies: 0
    Last Post: 05-11-2009, 01:42 AM
  2. writing data to a file from an array of pointers
    By Mingzhi in forum C++ Programming
    Replies: 1
    Last Post: 07-19-2004, 09:07 AM
  3. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM
  4. Help with an Array
    By omalleys in forum C Programming
    Replies: 1
    Last Post: 07-01-2002, 08:31 AM
  5. Replies: 5
    Last Post: 11-20-2001, 12:48 PM