以下是我正在编写的C程序的第一部分。然而,gcc在编译期间抛出错误,导致set
,p
和s1
都未声明,但它们被声明。我对这个文件中的每个函数都有这个问题,我不知道出了什么问题。我该怎么做才能解决问题?
此功能的具体错误:
a9.c: In function `makeaset':
a9.c:23: error: `set' undeclared (first use in this function)
a9.c:23: error: (Each undeclared identifier is reported only once
a9.c:23: error: for each function it appears in.)
a9.c:23: error: `p' undeclared (first use in this function)
a9.c:34: error: `s1' undeclared (first use in this function)
代码段:
#include <stdio.h>
#include <stdlib.h>
#define SIZE 32
struct set {
char *data;
int count;
};
typedef struct set set;
void makeaset(set **s1)
{
int i;
set *p;
p = NULL;
p = malloc(sizeof(set));
if (p) {
p->data = malloc(SIZE);
if (p->data) {
for (i = 0; i < SIZE; i++)
p->data[i] = 0;
p->count = 0;
}
}
*s1 = p;
}
答案 0 :(得分:0)
尝试
struct set_struct {
char *data;
int count;
};
typedef struct set_struct set;
或类似的东西。