jeudi 11 avril 2019

Why is the compiler giving and error {use of undeclared identifier 'Events'} and compile this program successfully?

The output must look like this

I am writing a program that reads input from a file and stores it into struct. It also prints out the data in a table format.

I have written the code to solve this challenge but I am getting errors and need help in resolving them.

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

enum eType {eBirthday, eWedding, eConference, eMeeting};

struct Date
{
    double Day;
    double Month;
    double Year;
};

struct Time
{
    double Hour;
    double Minute;
    double Second;
 };
 struct Events
 {
     char ID[8]; // id is defined as char with 8 array spaces
     enum eType EventType;
     char Location[30];
     struct Time;
     struct Date;
 };

int main()
struct Events[];
FILE *fptr;

if ((fptr = fopen("test1.txt","r")) == NULL){
    printf("Error! opening file");
    exit(1); // Program exits if the file pointer returns NULL.
}

int i;
for (int i=0; i<31, i++);
{
    if(fscanf(fptr,"%s\n",Events[i].ID)==EOF) break; // eof reached

    fscanf(fptr,"%e\n",Events[i].EventType)

    EventType ExtractType(char *Type); // returns event enum from string Type

    fgets(Events[i].Location, 30, fptr);

    Events[i].Location[strlen(Events[i].Location)-1] = '\0'; // remove \n from the string

    fscanf(fptr, "%d/%d/%d\n", &(Events[i].Date.Day),&(Events[i].Date.Month), &(Events[i].Date.Year));

    fscanf(fptr, "%d:%d:%d\n", &(Events[i].Time.Hour), &(Events[i].Date.Minute), &(Events[i].Date.Second));
}

    printf("ID \tPrice \tLocation \tDate \tTime \n");  //\t gives a tab
    printf("------------------------------------------------------------- \n"); //prints a line of dashes

    for (int i = 0; i <31; i++)
    {
         printf("%s \t%c \t %c \t", Events[i].ID, Events[i].EventType, Events[i].Location);
         printf("%02d/%02d/%02d\t", Events[i].Date.Day,Events[i].Date.Month, Events[i].Date.Year);
         printf("%02d:%02d:%02d\n", Events[i].Time.Hour,Events[i].Time.Minute, Events[i].Time.Second);
}

fclose(fptr);

return 0;

}

The output must look like this

Aucun commentaire:

Enregistrer un commentaire