0

I have a problem with a C Program, I have a struct for Client

    typedef struct Date{
    int Day;
    int Month;
    int Year;
}Date;
typedef struct Client{
    char LNAME[26];
    char FNAME[26];
    char PHONE[15];
    char EMAIL[51];
    char PERMIT[26];
    char CIN[26];
    Date BDAY;
}Client;

and a function that will return a struct of type "Client" after searching in a specific file.

Client GetClient(char C[]){
FILE *clients;
    Client res;
    char cin[26], lname[26], fname[26], a[100], b[100], c[100];
    int d,e,f;
    clients = fopen("Clients.txt","r");
        while(!feof(clients))
        {
            fscanf(clients,"%s\t| %s\t| %s\t| %s\t| %s\t| %s\t| %d/%d/%d\n",&cin,&lname,&fname,&a,&b,&c,&d,&e,&f);
            if(!strcmp(C,cin))
            {
                res.BDAY.Day=d; res.BDAY.Month=e; res.BDAY.Year=f;
                strcpy(res.CIN,cin); strcpy(res.LNAME,lname); strcpy(res.FNAME,fname);
                strcpy(res.PERMIT,a); strcpy(res.PHONE,b); strcpy(res.EMAIL,c);
                break;
            }
        }
    fclose(clients);
    return res;
}

In the main file, I'm trying to consume this function by

Client ClientToShow = GetClient(CIN);

But I'm getting this error [Error] invalid initializer I'm using DevC++ 5.11 with GCC on Windows

Mo-
  • 155
  • 15
  • Will only work if `ClientToShow` is a locally defined variable. You cannot call a function at file scope. – Weather Vane Apr 02 '17 at 17:02
  • 1
    Unrelated to your problem, but you should read [Why is “while ( !feof (file) )” always wrong?](http://stackoverflow.com/questions/5431941/why-is-while-feof-file-always-wrong). – Some programmer dude Apr 02 '17 at 17:04
  • Well, The struct & the function are defined in another file. @Someprogrammerdude Thanks! I'm just doing a proof of concept :) – Mo- Apr 02 '17 at 17:15

0 Answers0