Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

including header file in two .c files

Tags:

c

The program should save a couple of points and put them out on request. The program contains one .h file and two .c files. This is the compiler info i get:

prog.c:46:25: fatal error: pointstack.h: No such file or directory #include "pointstack.h"

What did I miss?

//File: pointStack.h - Headerfile 

#ifndef POINTSTACK_H
#define POINTSTACK_H


#include <stdio.h>
#include <stdlib.h>


//structs

//struct for coordinates

struct point
{
    float rX;
    float rY;
    float rZ;
};
typedef struct point POINT;

struct stackPoint
{
    POINT p;
    struct stackPoint *next;
};
typedef struct stackPoint STACK_POINT;
typedef STACK_POINT *STACK_POINT_PTR;

//functions


void push(POINT pushPoint);
POINT pop();
int isEmpty();
void printStackElement(POINT aPoint);

#endif
//File: pointstack.c - functions of stack program

#include "pointstack.h" 


//global variable

STACK_POINT_PTR stackTop = NULL;

void push(POINT pushPoint) 
{

//temporary variable 

    STACK_POINT_PTR stackPoint = (STACK_POINT_PTR) malloc(sizeof(STACK_POINT));


//in case there is not enough memory

    if(stackPoint == NULL)
    {
        printf("not enough memory ... End \n");
        exit(1);
    }


//save point

    stackPoint->p = pushPoint;
    stackPoint->next = stackTop;
    stackTop = stackPoint;

    return;
}

POINT pop() 
{

//save stackTop and nextStackTop

    STACK_POINT firstStackPoint = *stackTop;

    free(stackTop);

    stackTop = firstStackPoint.next;

    return firstStackPoint.p;
}

int isEmpty()
{   
    if(stackTop == NULL)
    {
        return 1;
    }
    else {
        return 0;
    }
}


void printStackElement(POINT aPoint)
{
    printf("Point x: %f, Point y: %f, Point z: %f \n", aPoint.rX, aPoint.rY, aPoint.rZ);
    return;
}
//File: stackmain.c 


#include "pointstack.h"

void exit(int);

POINT readPoint() 
{
    POINT userPoint;

    printf("x-coordinate \n");
    scanf("%62f", &userPoint.rX);
    printf("y-coordinate \n");
    scanf("%62f", &userPoint.rY);
    printf("z-coordinate \n");
    scanf("%62f", &userPoint.rZ);

    return userPoint;
}


int main(void)
{

//declaration

    char cCmd;

    printf("’p’ for input, ’q’ for output: \n");

    while(1)
    {

        scanf("%c", &cCmd);

        if(cCmd == 'p') 
        {
            push(readPoint());
            printf("’p’ for input, ’q’ for output: \n");       
        }

        if(cCmd == 'q')
        {
            while(!isEmpty())
            {
                printStackElement(pop());
            }
            break;
        }
    }

    return 0;
}
like image 715
haziel k Avatar asked Mar 18 '23 16:03

haziel k


1 Answers

What you missed is that your file is called pointStack.h with a capital S, not pointstack.h with a lower case s.

like image 82
Daniel Avatar answered Mar 28 '23 02:03

Daniel