gpt4 book ai didi

c - header 中定义的 TypeDef 结构

转载 作者:太空宇宙 更新时间:2023-11-04 07:06:17 26 4
gpt4 key购买 nike

作业.h

#ifdef HOMEWORK_H_
#define HOMEWORK_H_

typedef struct
{
int IDNumber;
char FirstName[30];
char LastName[30];
}Student;

int AddStudent();
#endif

GradeFunctions.c

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "Homework.h"

#define MAX 100

int AddStudent()
{
int i;
int StuNumber = 0;

Student store[MAX];

for(i = 0; i < 0; i++)
{
if(Strlen(store[i].FirstName) > 0)
{
if(Strlen(store[i].LastName) > 0)
{
if(Strlen(store[i].IDNumber) > 0)
{
int StuNumber = i;
break;
}
}
}
}
printf("Please enter the students first name: ");
scanf("%s", store[StuNumber].FirstName);
printf("\n");
printf("Please enter the students last name: ");
scanf("%s", store[StuNumber].LastName);
printf("\n");
printf("Please enter the students ID Number: ");
scanf("%d", &store[StuNumber].IDNumber);
printf("\n");
return 0;
}

我每次尝试编译时都会收到这个错误

GradeFunctions.c: In function ‘AddStudent’:
GradeFunctions.c:13:2: error: unknown type name ‘Student’
GradeFunctions.c:17:21: error: request for member ‘FirstName’ in something not a structure or union
GradeFunctions.c:19:22: error: request for member ‘LastName’ in something not a structure or union
GradeFunctions.c:21:23: error: request for member ‘IDNumber’ in something not a structure or union
GradeFunctions.c:30:30: error: request for member ‘FirstName’ in something not a structure or union
GradeFunctions.c:33:30: error: request for member ‘LastName’ in something not a structure or union
GradeFunctions.c:36:31: error: request for member ‘IDNumber’ in something not a structure or union

在过去的几个小时里,我一直试图在我的教科书和网上找到发生这种情况的原因,但无济于事。我做错了什么?

最佳答案

#ifdef HOMEWORK_H_

应该是

#ifndef HOMEWORK_H_
^^^ Missing n

因为该文件的内容不包含在代码库中。

关于c - header 中定义的 TypeDef 结构,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32674776/

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