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

1. ## 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

grunente@aol.com

2. 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];```

3. ## #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. 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. #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.

6. 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.