[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 435
  • Last Modified:

[Simple] C Program Errors

I am trying to compile my C program and one of my header files is giving me alot of problems. How can I fix all of these errors?

linkedlist.h:7: warning: useless storage class specifier in empty declaration
linkedlist.h:12: error: expected specifier-qualifier-list before âNODEâ
linkedlist.h:23: error: expected â=â, â,â, â;â, âasmâ or â__attribute__â before ânewentryâ
linkedlist.h:25: error: expected â=â, â,â, â;â, âasmâ or â__attribute__â before âremoveentryâ


#ifndef __LINKEDLIST_H
#define __LINKEDLIST_H
 
#define MAX_NAME_LENGTH 25
#define PHONE_NUMBER_LENGTH 12
 
typedef struct NODE;
typedef struct {
        char firstName[MAX_NAME_LENGTH];
        char lastName[MAX_NAME_LENGTH];
        char phoneNumber[PHONE_NUMBER_LENGTH];
        NODE *previousNode;
        NODE *nextNode;
} NODE;
 
typedef struct {
        NODE *firstNode;
        NODE *lastNode;
        NODE *currentNode;
        int counter;
} LINKEDLIST;
 
bool newentry(LINKEDLIST *myLinkedList, char *firstName, char *lastName, char *phoneNumber);
void displayall(LINKEDLIST myLinkedList);
bool removeentry(LINKEDLIST *myLinkedList, char *phoneNumber);
 
#endif

Open in new window

0
bejhan
Asked:
bejhan
  • 3
  • 2
1 Solution
 
Infinity08Commented:
Use :

        typedef struct NODE {
                char firstName[MAX_NAME_LENGTH];
                char lastName[MAX_NAME_LENGTH];
                char phoneNumber[PHONE_NUMBER_LENGTH];
                struct NODE *previousNode;
                struct NODE *nextNode;
        } NODE;

instead of :

        typedef struct NODE;
        typedef struct {
                char firstName[MAX_NAME_LENGTH];
                char lastName[MAX_NAME_LENGTH];
                char phoneNumber[PHONE_NUMBER_LENGTH];
                NODE *previousNode;
                NODE *nextNode;
        } NODE;

Also, bool is not a valid type in C, so you'll have to either define it somewhere, or choose a different type.
0
 
Infinity08Commented:
For example :
#ifndef __LINKEDLIST_H
#define __LINKEDLIST_H
 
#define MAX_NAME_LENGTH 25
#define PHONE_NUMBER_LENGTH 12
 
 
/*typedef struct NODE;*/                          /* <--- this line is removed !! */
typedef struct NODE {
        char firstName[MAX_NAME_LENGTH];
        char lastName[MAX_NAME_LENGTH];
        char phoneNumber[PHONE_NUMBER_LENGTH];
        struct NODE *previousNode;                /* <--- use struct NODE* here */
        struct NODE *nextNode;
} NODE;
 
typedef struct {
        NODE *firstNode;
        NODE *lastNode;
        NODE *currentNode;
        int counter;
} LINKEDLIST;
 
typedef int bool;                                 /* <--- add this */
 
bool newentry(LINKEDLIST *myLinkedList, char *firstName, char *lastName, char *phoneNumber);
void displayall(LINKEDLIST myLinkedList);
bool removeentry(LINKEDLIST *myLinkedList, char *phoneNumber);
 
#endif

Open in new window

0
 
bejhanAuthor Commented:
I included stdbool.h to fix the bool error but still get

linkedlist.h:12: error: expected specifier-qualifier-list before âNODEâ

even with your change.
0
 
bejhanAuthor Commented:
Didn't see to add struct in front of the NODE elements. Works now.
0
 
Infinity08Commented:
>> Works now.

Great :)
0

Featured Post

Live webcast with Pinal Dave

Pinal Dave will teach you tricks to help identify the real root cause of database problems rather than red herrings. Attendees will learn scripts that they can use in their environment to immediately figure out their performance Blame Shifters and fix them quickly.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now