gpt4 book ai didi

c - 在两个 .c 文件中包含头文件

转载 作者:行者123 更新时间:2023-12-03 22:24:24 24 4
gpt4 key购买 nike

该程序应该保存几个点并根据要求将它们输出。
该程序包含一个 .h 文件和两个 .c 文件。
这是我得到的编译器信息:

prog.c:46:25: fatal error : pointstack.h: 没有这样的文件或目录 #include "pointstack.h"

我错过了什么?

//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;
}

最佳答案

您错过的是您的文件名为 pointStack.h大写的 S,而不是 pointstack.h小写 s。

关于c - 在两个 .c 文件中包含头文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27431934/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com