-2
#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;
}

Hello, I get an error at the line load(struct lottery array); in my main function. The error says Expected expression before struct. I googled it and I couldn't understand why would it expect an expression there and I am kinda confused.

CristiFati
  • 38,250
  • 9
  • 50
  • 87
Edward
  • 47
  • 1
  • 9

2 Answers2

1

The problem is with the function call. In your code, you've written

 load(struct lottery array);

which is wrong. You should pass only the variable as the argument, like

load(array);

That said, your fopen() failure check and subsequent code also looks wrong. You're checking for the failure case but continue to use the returned pointer anyway, which kinds of nullifies the effect of having the check in the first place.

Sourav Ghosh
  • 133,132
  • 16
  • 183
  • 261
  • @Edward You're welcome. You can also [consider accepting an answer that helped you](http://meta.stackexchange.com/q/5234/244062). – Sourav Ghosh Jan 20 '17 at 17:45
1

Parameters passed to functions when calling them are just variables - you don't need to include the data types as well. So the line

load(struct lottery array);

should just be

load(array);
Chris Turner
  • 8,082
  • 1
  • 14
  • 18