Thread: array type has incomplete element type

  1. #1
    Registered User
    Join Date
    Jan 2018
    Posts
    2

    array type has incomplete element type

    hello I've just been trying to get this lines of code to compile in gcc. It does in visual studio 2017 so I just don't really understand this errors
    Code:
     
    In file included from contacts.c:19:0:
    contactHelpers.h:54:35: error: array type has incomplete element type
    contactHelpers.h:54:35: warning: ‘struct Contact’ declared inside parameter list [enabled by default]
    contactHelpers.h:54:35: warning: its scope is only this definition or declaration, which is probably not what you want [enabled by default]
    contactHelpers.h:63:34: warning: ‘struct Contact’ declared inside parameter list [enabled by default]
    contactHelpers.h:66:35: error: array type has incomplete element type
    contactHelpers.h:66:35: warning: ‘struct Contact’ declared inside parameter list [enabled by default]
    contactHelpers.h:69:34: error: array type has incomplete element type
    contactHelpers.h:69:34: warning: ‘struct Contact’ declared inside parameter list [enabled by default]
    contactHelpers.h:72:24: error: array type has incomplete element type
    contactHelpers.h:72:24: warning: ‘struct Contact’ declared inside parameter list [enabled by default]
    contactHelpers.h:75:27: error: array type has incomplete element type
    contactHelpers.h:75:27: warning: ‘struct Contact’ declared inside parameter list [enabled by default]
    contactHelpers.h:78:27: error: array type has incomplete element type
    contactHelpers.h:78:27: warning: ‘struct Contact’ declared inside parameter list [enabled by default]
    In file included from contactHelpers.c:23:0:
    contactHelpers.h:54:35: error: array type has incomplete element type
    contactHelpers.h:54:35: warning: ‘struct Contact’ declared inside parameter list [enabled by default]
    contactHelpers.h:54:35: warning: its scope is only this definition or declaration, which is probably not what you want [enabled by default]
    contactHelpers.h:63:34: warning: ‘struct Contact’ declared inside parameter list [enabled by default]
    contactHelpers.h:66:35: error: array type has incomplete element type
    contactHelpers.h:66:35: warning: ‘struct Contact’ declared inside parameter list [enabled by default]
    contactHelpers.h:69:34: error: array type has incomplete element type
    contactHelpers.h:69:34: warning: ‘struct Contact’ declared inside parameter list [enabled by default]
    contactHelpers.h:72:24: error: array type has incomplete element type
    contactHelpers.h:72:24: warning: ‘struct Contact’ declared inside parameter list [enabled by default]
    contactHelpers.h:75:27: error: array type has incomplete element type
    contactHelpers.h:75:27: warning: ‘struct Contact’ declared inside parameter list [enabled by default]
    contactHelpers.h:78:27: error: array type has incomplete element type
    contactHelpers.h:78:27: warning: ‘struct Contact’ declared inside parameter list [enabled by default]
    contactHelpers.c: In function ‘ContactManagerSystem’:
    contactHelpers.c:178:4: error: type of formal parameter 1 is incomplete
    contactHelpers.c:183:4: error: type of formal parameter 1 is incomplete
    contactHelpers.c:188:4: error: type of formal parameter 1 is incomplete
    contactHelpers.c:193:4: error: type of formal parameter 1 is incomplete
    contactHelpers.c:198:4: error: type of formal parameter 1 is incomplete
    contactHelpers.c: At top level:
    contactHelpers.c:269:6: error: conflicting types for ‘displayContact’
    contactHelpers.h:63:6: note: previous declaration of ‘displayContact’ was here
    contactHelpers.c:178: confused by earlier errors, bailing out
    here are my code:
    contactHelpers.h
    Code:
    #ifndef contactHelpers_H
    
    
    #define contactHelpers_H
    
    // Clear the standard input buffer
    // clearKeyboard:
    void clearKeyboard(void);
    
    // pause:
    void pause(void);
    
    // getInt:
    int getInt(void);
    
    // getIntInRange:
    int getIntInRange(int minRange, int Maxrange);
    
    // yes:
    int yes(void);
    
    // menu:
    int menu(void);
    
    // ContactManagerSystem:
    void ContactManagerSystem(void);
    
    // Generic function to get a ten-digit phone number:
    // getTenDigitPhone:
    void getTenDigitPhone(char[]);
    
    // findContactIndex:
    int findContactIndex(const struct Contact[], int, const char[]);
    
    // displayContactHeader:
    void displaycontactHeader(void);
    
    // displayContactFooter:
    void displayContactFooter(int);
    
    // displayContact:
    void displayContact(const struct Contact*);
    
    // displayContacts:
    void displayContacts(const struct Contact[], int);
    
    // searchContacts:
    void searchContacts(const struct Contact[], int);
    
    // addContact:
    void addContact(struct Contact[], int);
    
    // updateContact:
    void updateContact(struct Contact[], int);
    
    // deleteContact:
    void deleteContact(struct Contact[], int);
    
    #endif // !contactHelpers_H
    contacts.h
    Code:
    ifndef CONTACTS_H_
    #define CONTACTS_H_
    
    #include <stdio.h>
    
    
    struct Name
    {
        char firstName[31];
        char middleName[7];
        char lastName[36];
    };
    
    struct Address
    {
        int streetNumber;
        char street[41];
        int apartmentNumber;
        char postalCode[8];
        char city[41];
    };
    
    struct Numbers
    {
        char cell[11];
        char home[11];
        char business[11];
    };
    
    struct Contact
    {
        struct Name name;
        struct Address address;
        struct Numbers numbers;
    };
    
    void displayTitle (void);
    
    void getName (struct Name *);
    
    void getAddress (struct Address *);
    
    void getNumbers (struct Numbers *);
    
    void getContact(struct Contact *);
    
    
    #endif // !CONTACTS_H_
    a2ms4.c
    Code:
    #define _CRT_SECURE_NO_WARNINGS
    
    #include <stdio.h>
    #include "contacts.h"
    #include "contactHelpers.h"
    
    void printSectionHeader(const char*);
    
    int main(void)
    {
        ContactManagerSystem();
    
        return 0;
    }
    
    // Display specified test section header
    void printSectionHeader(const char* testName)
    {
        printf("\n");
        printf("------------------------------------------\n");
        printf("Testing: %s\n", testName);
        printf("------------------------------------------\n");
    }
    contacts.c
    Code:
    #define _CRT_SECURE_NO_WARNINGS
    
    #include <stdio.h>
    
    
    #include "contactHelpers.h"
    #include "contacts.h"
    
    
    // getName:
    void getName(struct Name * name) {
        int yesNo = 0;
        printf("Please enter the contact's first name: ");
        scanf(" %[^\n]", name->firstName);
        clearKeyboard();
        printf("Do you want to enter a middle initial(s)? (y or n): ");
        yesNo = yes();
        if (yesNo == 1) {
            printf("Please enter the contact's middle initial(s): ");
            scanf(" %[^\n]", name->middleInitial);
            clearKeyboard();
        }
    
        printf("Please enter the contact's last name: ");
        scanf(" %[^\n]", name->lastName);
        clearKeyboard();
    }
    // getAddress:
    void getAddress(struct Address * address) {
        int yesNo = 0;
        printf("Please enter the contact's street number: ");
        address->streetNumber = getInt();
        if (address->streetNumber > 0) {
        }
        else {
            printf("*** INVALID INTEGER *** <Please enter an integer>: ");
            address->streetNumber = getInt();
        }
        printf("Please enter the contact's street name: ");
        scanf(" %40[^\n]", address->street);
        clearKeyboard();
        printf("Do you want to enter an apartment number? (y or n): ");
        yesNo = yes();
        if (yesNo == 1) {
            printf("Please enter the contact's apartment number: ");
            address->apartmentNumber = getInt();
            if (address->apartmentNumber > 0) {
            }
            else {
                printf("*** INVALID INTEGER *** <Please enter an integer>: ");
                address->apartmentNumber = getInt();
            }
        }
        printf("Please enter the contact's postal code: ");
        scanf(" %7[^\n]", address->postalCode);
        clearKeyboard();
        printf("Please enter the contact's city: ");
        scanf(" %40[^\n]", address->city);
        clearKeyboard();
    }
    
    // getNumbers:
    void getNumbers(struct Numbers * numbers) {
        int yesNo = 0;
        printf("Please enter the contact's cell phone number: ");
        getTenDigitPhone(numbers->cell);
        printf("Do you want to enter a home phone number? (y or n): ");
        yesNo = yes();
        if (yesNo == 1) {
            printf("Please enter the contact's home phone number: ");
            getTenDigitPhone(numbers->home);
        }
    
        printf("Do you want to enter a business phone number? (y or n): ");
        yesNo = yes();
        if (yesNo == 1) {
            printf("Please enter the contact's business phone number: ");
            getTenDigitPhone(numbers->business);
        }
    }
    // getContact:
    void getContact(struct Contact * contact) {
        getName(&contact->name);
        getAddress(&contact->address);
        getNumbers(&contact->numbers);
    }
    contactHelpers.c
    Code:
    #define _CRT_SECURE_NO_WARNINGS
    
    #include <stdio.h>
    
    
    #include <string.h>
    // ----------------------------------------------------------
    #include "contactHelpers.h"
    #include "contacts.h"
    
    
    #define MAXCONTACTS 5
    
    
    // clearKeyboard
    void clearKeyboard(void)
    {
        while (getchar() != '\n')
            ; 
    }
    
    // pause:
    void pause(void)
    {
        printf("(Press Enter to Continue)");
        clearKeyboard();
    }
    
    // getInt:
    int getInt(void)
    {
        char NL = 'x';
        int value = 0;
        int boolean = 0;
    
        scanf(" %d%c", &value, &NL);
    
        do {
            if (NL != '\n') {
                clearKeyboard();
                printf("*** INVALID INTEGER *** <Please enter an integer>: ");
                scanf(" %d%c", &value, &NL);
                boolean = 1;
            }
            else {
                boolean = 0;
            }
        } while (boolean == 1);
        return value;
    }
    
    // getIntInRange:
    int getIntInRange(int minRange, int maxRange)
    {
        int tstInteger;
        int boolean = 0;
    
        tstInteger = getInt();
        do {
            if (tstInteger < minRange || tstInteger > maxRange) {
                printf("*** OUT OF RANGE *** <Enter a number between %d and %d>: ", minRange, maxRange);
                tstInteger = getInt();
                boolean = 1;
            }
            else {
                boolean = 0;
            }
        } while (boolean != 0);
        return tstInteger;
    }
    
    // yes:
    int yes(void)
    {
        int boolean = 0;
        int result = 0;
        char input;
        char NL = 'x';
        do {
            scanf(" %c%c", &input, &NL);
    
            if (NL != '\n') {
                printf("*** INVALID ENTRY *** <Only (Y)es or (N)o are acceptable>: ");
                boolean = 1;
            }
            else {
                switch (input) {
                case 'Y':
                case 'y':
                    result = 1;
                    boolean = 0;
                    break;
                case 'N':
                case'n':
                    result = 0;
                    boolean = 0;
                    break;
                }
            }
        } while (boolean == 1);
        return result;
    }
    
    // menu:
    int menu(void)
    {
        int input = 0;
        printf("Contact Management System\n");
        printf("-------------------------\n");
        printf("1. Display contacts\n");
        printf("2. Add a contact\n");
        printf("3. Update a contact\n");
        printf("4. Delete a contact\n");
        printf("5. Search contacts by cell phone number\n");
        printf("6. Sort contacts by cell phone number\n");
        printf("0. Exit\n\n");
        printf("Select an option:> ");
    
        input = getIntInRange(0, 6);
        printf("\n");
    
        return input;
    }
    
    // ContactManagerSystem:
    void ContactManagerSystem(void)
    {
        struct Contact contact[MAXCONTACTS] =
        { { { "Rick",{ '\0' }, "Grimes" },
        { 11, "Trailer Park", 0, "A7A 2J2", "King City" },
        { "4161112222", "2162223333", "4163334444" } },
        {
            { "Maggie", "R.", "Greene" },
            { 55, "Hightop House", 0, "A9A 3K3", "Bolton" },
            { "9051112222", "9052223333", "9053334444" } },
            {
                { "Morgan", "A.", "Jones" },
                { 77, "Cottage Lane", 0, "C7C 9Q9", "Peterborough" },
                { "7051112222", "7052223333", "7053334444" } },
                {
                    { "Sasha",{ '\0' }, "Williams" },
                    { 55, "Hightop House", 0, "A9A 3K3", "Bolton" },
                    { "9052223333", "9052223333", "9054445555" } },
        };
    
        int menuInput = 0;
        int exitInput = 0;
        int boolean = 0;
    
        do {
            menuInput = menu();
            switch (menuInput) {
            case 1:
                displayContacts(contact, MAXCONTACTS);
                pause();
                printf("\n");
                break;
            case 2:
                addContact(contact, MAXCONTACTS);
                pause();
                printf("\n");
                break;
            case 3:
                updateContact(contact, MAXCONTACTS);
                pause();
                printf("\n");
                break;
            case 4:
                deleteContact(contact, MAXCONTACTS);
                pause();
                printf("\n");
                break;
            case 5:
                searchContacts(contact, MAXCONTACTS);
                pause();
                printf("\n");
                break;
            case 6:
                printf("<<< Feature to sort is unavailable >>>\n");
                pause();
                break;
            case 0:
                printf("Exit the program? (Y)es/(N)o: ");
                exitInput = yes();
                printf("\n");
                if (exitInput == 1) {
                    printf("Contact Management System: terminated");
                    printf("\n");
                    boolean = 1;
                }
            }
        } while (boolean == 0);
    }
    
    // getTenDigitPhone
    void getTenDigitPhone(char telNum[11])
    {
        int needInput = 1;
    
        while (needInput == 1) {
            scanf("%10s", telNum);
            clearKeyboard();
    
            if (strlen(telNum) == 10)
                needInput = 0;
            else
                printf("Enter a 10-digit phone number: ");
        }
    }
    
    // findContactIndex:
    int findContactIndex(const struct Contact contact[], int size, const char cellNum[])
    {
        int i = 0;
        int output;
        for (i = 0; i < size; i++) {
            output = strcmp(contact[i].numbers.cell, cellNum);
            if (output == 0) {
                return i;
            }
        }
        return -1;
    }
    
    // displayContactHeader
    void displayContactHeader(void) {
        printf("+-----------------------------------------------------------------------------+\n");
        printf("|                              Contacts Listing                               |\n");
        printf("+-----------------------------------------------------------------------------+\n");
    }
    
    // displayContactFooter
    void displayContactFooter(int totalContact) {
        printf("+-----------------------------------------------------------------------------+\n");
        printf("Total contacts: %d\n\n", totalContact);
    }
    
    // displayContact:
    void displayContact(const struct Contact* contact) {
        if (contact->name.middleInitial[0] != '\0') {
            printf("%s %s %s\n", contact->name.firstName, contact->name.middleInitial, contact->name.lastName);
        }
        else {
            printf("%s %s\n", contact->name.firstName, contact->name.lastName);
        }
        printf("    C: %-10s    H: %-10s    B: %-10s\n", contact->numbers.cell, contact->numbers.home, contact->numbers.business);
        printf("       %d %s, ", contact->address.streetNumber, contact->address.street);
        if (contact->address.apartmentNumber > 0) {
            printf("Apt# %d, ", contact->address.apartmentNumber);
        }
        printf("%s, %s\n", contact->address.city, contact->address.postalCode);
    }
    
    // displayContacts:
    void displayContacts(const struct Contact contact[], int num) {
        int i;
        int totalContact = 0;
    
        displayContactHeader();
    
        for (i = 0; i < num; i++) {
            if (strlen(contact[i].numbers.cell) > 0) {
                displayContact(&contact[i]);
                totalContact++;
            }
        }
        displayContactFooter(totalContact);
    }
    
    // searchContacts:
    void searchContacts(const struct Contact contact[], int num) {
        char cellNum[11];
        int contactIndex = 0;
    
        printf("Enter the cell number for the contact: ");
        getTenDigitPhone(cellNum);
        contactIndex = findContactIndex(contact, num, cellNum);
    
        if (contactIndex == -1) {
            printf("*** Contact NOT FOUND ***\n");
        }
        else {
            printf("\n");
            displayContact(&contact[contactIndex]);
            printf("\n");
        }
    }
    
    // addContact:
    void addContact(struct Contact contact[], int num) {
        char emptyIndex[11] = { '\0' };
        int newContact;
        struct Contact tempContact = { { { 0 } } };
    
        newContact = findContactIndex(contact, num, emptyIndex);
    
        if (newContact != -1) {
            getContact(&tempContact);
            contact[newContact] = tempContact;
            printf("--- New contact added! ---\n");
        }
        else {
            printf("*** ERROR: The contact list is full! ***\n");
        }
    }
    
    // updateContact:
    void updateContact(struct Contact contact[], int i) {
        char contactInput[11] = { '\0' };
        int input = 0;
        int contactIndex;
        int contactIn;
        printf("Enter the cell phone number for the contact: ");
        getTenDigitPhone(contactInput);
        contactIndex = findContactIndex(contact, i, contactInput);
        contactIn = findContactIndex(contact, i, contactInput);
    
        if (contactIn == -1) {
            printf("*** Contact NOT FOUND ***\n");
        }
        else {
            printf("\nContact found:\n");
            displayContact(&contact[contactIndex]);
    
            printf("Do you want to update the name? (y or n): ");
            input = yes();
    
            if (input == 1) {
                getName(&contact[contactIndex].name);
            }
            printf("Do you want to update the address? (y or n): ");
            input = yes();
    
            if (input == 1) {
                getAddress(&contact[contactIndex].address);
            }
            printf("Do you want to update the numbers? (y or n): ");
            input = yes();
    
            if (input == 1) {
                getNumbers(&contact[contactIndex].numbers);
            }
    
            printf("--- Contact Updated! ---\n");
        }
    }
    
    // deleteContact:
    void deleteContact(struct Contact contact[], int i) {
        char contactInput[11] = { '\0' };
        int input = 0;
        int contactIndex;
    
        printf("Enter the cell phone number for the contact: ");
        getTenDigitPhone(contactInput);
    
        contactIndex = findContactIndex(contact, i, contactInput);
    
        if (contactIndex == -1)
            printf("*** Contact NOT FOUND ***\n");
    
        else {
            printf("\nContact found:\n");
    
            displayContact(&contact[contactIndex]);
            printf("\n");
    
            printf("CONFIRM: Delete this contact? (y or n): ");
            input = yes();
    
            if (input == 1) {
                contact[contactIndex].numbers.cell[0] = '\0';
                printf("--- Contact deleted! ---\n");
            }
        }
    }
    how can I fix my errors? thank you for the help!

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,662
    Check the order you include files.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Jan 2018
    Posts
    2
    Quote Originally Posted by Salem View Post
    Check the order you include files.
    Thank you it worked, can't believe I spent hours on that. I need more practice, still a newb.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Array Type Has Incomplete Element Type
    By RocketMan46 in forum C Programming
    Replies: 20
    Last Post: 07-04-2015, 09:25 AM
  2. Replies: 2
    Last Post: 05-23-2011, 02:04 PM
  3. array type has incomplete element type
    By philgrek in forum C Programming
    Replies: 29
    Last Post: 05-06-2011, 02:42 PM
  4. error: array type has incomplete element type
    By gerger in forum C Programming
    Replies: 8
    Last Post: 10-05-2010, 07:40 AM
  5. Incomplete type
    By nepper271 in forum C++ Programming
    Replies: 7
    Last Post: 01-29-2008, 11:54 AM

Tags for this Thread