pointers, structures, and arrays.... 
Author Message
 pointers, structures, and arrays....

Hi... I'm lost here.
Can anyone help me with this program?
My program is suppose to store and display words as well as its definitions,
and I'm trying to display the definitions of a single word, but to be honest I
don't know what to do.  Thanks in advance for all your suggestions.
This is what I have so far:

#define DEFLINE_MAX 3       /*Max number of lines when defining a word*/
#define ENTRY_MAX 50       /*Max number of words to be defined*/

struct word_entry                  /*Each word entry will consist of a
word...up to 80 chars*/
{                          /*  Defined by several lines(of max 80 char each)*/
        char keyword[80];          /*  The number of lines is determined by
DEFLINE_MAX*/
        char sentence[DEFLINE_MAX][80];

Quote:
};

struct word_entry dictionary[ENTRY_MAX];     /*Combine declaration with
definition*/
int entry_count = 0;                       /*Number of words currently in the
dictionary

int main(void)
{
        struct word_entry dictionary[ENTRY_MAX];
        int entry_count = 0;
        int index = 0;
        int option;

        while (option != 4)
        {
                printf("\n***Dictionary Menu***\n");
                printf("(1) Enter a definition\n");
                printf("(2) List all entries\n");
                printf("(3) Display an entry\n");
                printf("(4) Quit\n");
                printf("\n");
                printf("Enter Selection: ");
                scanf("%d", &option);

                switch(option)
                {
                        case(1):
                                index++;
                                word_entry_get_definition(index);
                                break;
                        case(2):
                                list_entries(index);
                                break;
                        case(3):
                                display_entry(dictionary, index);
                        case(4):
                                break;
                        default:
                                printf("Please select an option from the menu");
                }
        }
        printf("\nGood-bye!");
        return 0;

Quote:
}

        void word_entry_get_definition(int index)
        {
                int ct;
                int first;

                printf("Enter key word: ");
                fflush(stdout);
                if (entry_count<= ENTRY_MAX)
                scanf("%80s", dictionary[index].keyword);
                while (getchar() != '\n')
                printf("Enter definition of up to 3 lines.\n");
                for (ct = 0; ct < DEFLINE_MAX; ct ++)
                {
                        first = ct +1;
                        printf("Line %d: ", first);
                        gets(dictionary[index].sentence[ct]);
                        fflush(stdout);
                }
        }

        void list_entries(int index)
        {
                int word;

                printf("Dictionary Entries:\n");
                for (word = 0; word <= index; word++)
                printf("%s \n", dictionary[word].keyword);
        }

        void display_entry(struct word_entry * pst, int index)
        {
                int count;

                printf("Enter keyword to display:\n");
                scanf("%80s", dictionary[index].keyword);
                pst = &dictionary.sentence;
                for (count= 0; count< index; count++)
                        printf("%s \n", pst[count]->dictionary.sentence);
        }
--



Tue, 20 May 2003 03:00:00 GMT  
 pointers, structures, and arrays....

Quote:

> struct word_entry dictionary[ENTRY_MAX];     /*Combine declaration with
> definition*/

This definition...

Quote:
> int entry_count = 0;                          /*Number of words currently in the
> dictionary

> int main(void)
> {
>    struct word_entry dictionary[ENTRY_MAX];

...is hidden by this one.

Quote:
>                            word_entry_get_definition(index);

This function, because it does not get passed the main()-local
dictionary, uses the file scope one.

Quote:
>                            display_entry(dictionary, index);

This one, however, gets passed and uses the main() one; what's worse,
because its parameter is not called dictionary, but it does refer to
dictionary as well as to its parameter, it uses both.

Richard
--



Fri, 23 May 2003 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. pointers, structures, and arrays

2. An array in a structure Or an Array Of Structures

3. structure array pointer difficulties

4. Pointers in C and arrays of structures

5. Array of structures and pointers (again)

6. Returning pointer to array of structure from function

7. Pointers/Arrays of structures anyone??

8. A question about arrays,pointers and structures

9. pointers within an array of structures

10. Pointer to an array of structures

11. structure array pointer difficulties

12. structure array pointer difficulties

 

 
Powered by phpBB® Forum Software