gpt4 book ai didi

c - 我在 c 中编译此结构程序时出错

转载 作者:行者123 更新时间:2023-11-30 20:11:14 25 4
gpt4 key购买 nike

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

struct date {
int day;
int month;
int year;
};

struct lottery {
int aa;
struct date date1;
int n1;
int n2;
int n3;
int n4;
int n5;
int joker;
};

void load(struct lottery *array) {
FILE *fp;
fp = fopen("as.txt", "r");
if (fp == NULL)
printf("00000\n");
int i;
for (i = 0; i < 1; i++) {
fscanf(fp, "%d;%d/%d/%d;%d;%d;%d;%d;%d;%d", &array[i].aa, &array[i].date1.day, &array[i].date1.month, &array[i].date1.year, &array[i].n1, &array[i].n2, &array[i].n3, &array[i].n4, &array[i].n5, &array[i].joker);
if (feof(fp))
break;
}
array = (struct lottery*)realloc(array, i * sizeof(struct lottery));
// printf("%d;%d/%d/%d;%d;%d;%d;%d;%d;%d", array[0].aa, array[0].date1.day, array[0].date1.month, array[0].date1.year, array[0].n1, array[0].n2, array[0].n3, array[0].n4, array[0].n5, array[0].joker);
}

int main() {
struct lottery *array;
array = (struct lottery *)malloc(4 * sizeof(struct lottery));
// printf("%d", sizeof(struct lottery));
load(struct lottery array);
printf("%d",array[0].aa);

return 0;
}

您好,我在 load(struct lottery array); 行收到错误在我的 main 函数中。错误显示结构之前有预期的表达式。我用谷歌搜索了它,我不明白为什么它会期望那里有一个表达式,我有点困惑。

最佳答案

调用函数时传递给函数的参数只是变量 - 您不需要也包含数据类型。所以这条线

load(struct lottery array);

应该是

load(array);

关于c - 我在 c 中编译此结构程序时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41723828/

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