0

I can't get this code to work. It worked fine when it was all in one file, but when I split it up and put in the header file, I got all of these errors like (VERTEX has no member p) and (VERTEX has no member isVisited); strangely, no errors for C. What am I missing? What am I doing wrong?

#ifndef MY_HEADER_INCLUDED
#define MY_HEADER_INCLUDED

struct EDGETAG;
struct LINKTAG;
//struct VERTTAG;

typedef struct
{
    char c;
    bool isVisited;
    EDGE* p;
} VERTEX;

typedef struct EDGETAG
{
    VERTEX* v;
    struct EDGETAG* q;
} EDGE;



typedef struct LINKTAG
{
    VERTEX* v;
    struct LINKTAG* next;
} VERTLINK;

int main(int argc, char *argv[]);
void bredthfirst(VERTLINK * start, int numVerts);
void depthfirst(VERTLINK * start, int numVerts);
void depthfirst(VERTLINK * start, int numVerts);
void showchart(VERTLINK * start, int numVerts);

#endif

and here is a short sample from the file that contains main, near the bottom is where the errors where popping up

#include "myheader.h"
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>

int main(int argc, char *argv[])//(void)//
{
    FILE* fileAddress;
    int numVerts = 0;//0;
    int temper = 10;
    int * intArray;
    char templine[200];// = " ";//5];// = "  b";

    int getIndex = 0;
    int c = 0;
    int f = 0;
    int exitLoop = 0;
    bool vertfound = false;

    fileAddress = fopen(argv[1],"r");//

    int counter = 0;

    VERTLINK * currentlink;
    VERTLINK firstlink;
    VERTEX * tempvert;
    VERTEX * tempvertoo;
    EDGE * tempedge;
    EDGE * tempedgetoo;
    VERTLINK * templink;
    VERTLINK * templinktoo;
    while(fgets(templine, sizeof(templine), fileAddress) != NULL)
    {
        counter = 0;

         currentlink = &firstlink;

        while(templine[counter] == ' ')
        {
            counter++;
        }
        for(f = 0; f < numVerts; f++)
        {        
            if( (*(*currentlink).v).c == templine[counter])
            {
                vertfound = true;
                f = numVerts + 1;
            }
            else
            {
                if(f < numVerts - 1)// && numVerts != 6)
                {
                currentlink = (*currentlink).next;
                tempvert = (*currentlink).v;
                }


            }
        }
        if(vertfound)
        {vertfound = false;
        }
        else
        {
            if(numVerts == 0)
            {

                tempvert = malloc(sizeof (VERTEX));

                firstlink.v = tempvert;
                firstlink.next = NULL;
                (*firstlink.v).c = templine[counter];
                (*firstlink.v).isVisited = false;
                (*tempvert).p = NULL;

                numVerts++;
            }

Here is what the compiler said:

C:\...\CProject\finaldata\myheader.h|13|error: expected specifier-qualifier-list before 'bool'|
C:\...\CProject\finaldata\cgraph.c||In function 'main':|
C:\...\CProject\finaldata\cgraph.c|105|error: 'VERTEX' has no member named 'isVisited'|
C:\...\CProject\finaldata\cgraph.c|106|error: 'VERTEX' has no member named 'p'|
C:\...\CProject\finaldata\cgraph.c|126|error: 'VERTEX' has no member named 'p'|
C:\...\CProject\finaldata\cgraph.c|131|error: 'VERTEX' has no member named 'isVisited'|
C:\...\CProject\finaldata\cgraph.c|149|warning: comparison between pointer and integer|
C:\...\CProject\finaldata\cgraph.c|160|error: 'VERTEX' has no member named 'p'|
C:\...\CProject\finaldata\cgraph.c|164|error: 'VERTEX' has no member named 'p'|
C:\...\CProject\finaldata\cgraph.c|196|error: 'VERTEX' has no member named 'isVisited'|
C:\...\CProject\finaldata\cgraph.c|197|error: 'VERTEX' has no member named 'p'|
C:\...\CProject\finaldata\cgraph.c|221|error: 'VERTEX' has no member named 'p'|
C:\...\CProject\finaldata\cgraph.c|231|error: 'VERTEX' has no member named 'p'|
C:\...\CProject\finaldata\cgraph.c|271|error: 'VERTEX' has no member named 'isVisited'|
C:\...\CProject\finaldata\cgraph.c|273|error: 'VERTEX' has no member named 'p'|
C:\...\CProject\finaldata\cgraph.c|348|warning: implicit declaration of function 'topo'|
C:\...\CProject\finaldata\cgraph.c|361|error: 'VERTEX' has no member named 'p'|
C:\...\CProject\finaldata\cgraph.c|362|error: 'VERTEX' has no member named 'p'|
C:\...\CProject\finaldata\cgraph.c|388|error: 'VERTEX' has no member named 'p'|
C:\...\CProject\finaldata\cgraph.c|390|error: 'VERTEX' has no member named 'p'|
C:\...\CProject\finaldata\cgraph.c|391|error: 'VERTEX' has no member named 'p'|
C:\...\CProject\finaldata\cgraph.c|414|error: 'VERTEX' has no member named 'p'|
C:\...\CProject\finaldata\cgraph.c|415|error: 'VERTEX' has no member named 'p'|
||=== Build finished: 20 errors, 2 warnings ===|
Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278

3 Answers3

1
typedef struct
{
    char c;
    bool isVisited;
    struct EDGETAG* p;
} VERTEX;
Zhongzhi
  • 436
  • 3
  • 6
  • thankyou, but i am still getting the same result. I tried many ways, and they have all yielded the same result – user3051220 Dec 06 '13 at 05:00
  • 1
    @user3051220: are you still getting the error for `p` with what's above? For `bool`, you should include `stdbool.h` and make sure your compiler supports C99 (or above). – Mat Dec 06 '13 at 05:02
1

myheader.h|13|error: expected specifier-qualifier-list before 'bool'

You need to include stdbool.h before you use bool.

You also must declare EDGE before using it. There are probably other errors, but I haven't looked.

Jim Balter
  • 16,163
  • 3
  • 43
  • 66
1

In C, you need to include <stdbool.h> to get bool defined as a type.

You also have a pair of mutually recursive types. You can declare those in several ways, but the way I'd do it is this, using mixed-case names like Edge and Vertex in place of EDGE and VERTEX.

typedef struct Edge Edge;
typedef struct Vertex Vertex;

struct Vertex
{
    char c;
    bool isVisited;
    Edge* p;
};

struct Edge
{
    Vertex* v;
    Edge* q;
};

The two structure tags are mapped to the type name before either structure is defined.

This also avoids the SHOUTING. Consider types FILE and DIR as aberrations.

See also Should I use #include in headers?, How to structure #includes in C?, and Linking against a static library amongst other related questions.

Community
  • 1
  • 1
Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278