它在 pushintoset
中给出错误数组未声明的函数首次在此函数中使用
'->' 的类型参数无效(具有 'int')
#include <stdio.h>
#include <stdlib.h>
struct set
{
int data1;
int data2;
int size;
int *array;
int index;
};
struct set *createset(int capacity)
{
struct set * s = (struct set*)malloc(sizeof(struct set));
s->size = capacity;
s->array = (int *)malloc(sizeof(int) * s->size);
return s;
}
void pushintoset(struct set *st) //giving error in this function that array undeclared
{
int item1;
int item2;
int i;
for(i=0;i<5;i++)
{
printf("enter set %d \n",i);
scanf("%d %d",&item1,&item2);
st->index = i;
st->array[st->index]->data1 = item1;
st-array[st->index]->data2 = item2;
st->array[st->index]->index = i;
}
}
void printset(struct set * s)
{
int i;
for(i=1;i<=5;i++)
{
printf("%d \t %d \n",s->array[i]->data1,s->array[i]->data2);
}
}
int main()
{
struct set * se = createset(5);
if(se==NULL)``
printf("memory not allocate");
pushintoset(se);
printset(se);
return 0;
}
最佳答案
st-array[st->index]->data2 = item2; // loss of '>' after 'st-'
并且您不应该在此处将结构成员数组作为结构点进行访问。
关于c - 使用结构实现一组,但出现错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24795567/