i have previously created time using mktime and stored it in file, now the problem is how can i call it back and read as standard time, not an array. this is because i wanna make use of difftime function.

here is my code sample:

int ex(){
int typ;
    printf("\n\n\nEnter type parking: \n\tBudget =1\n\tPremium =2\n");
    scanf("%d", &typ);
    if (typ==1){
        FILE *cfPtr;
        struct budget newBudget={0, "", 0};
        if ((cfPtr = fopen("parking_budget.dat", "rb"))==NULL) {
        printf("File Could Not Open.\n");}
        printf("Enter parking no : ");
        int p;
        scanf("%d", &p);
            fseek(cfPtr, (p-1) * sizeof(struct budget), SEEK_SET);
            fread(&newBudget, sizeof (struct budget), 1, cfPtr);
                printf("\n%s", newBudget.plat);}

            time_t rawtime;
            struct tm * timeinfo;
            int year, month, day, hour, min;
            printf("Date and Time (year/month/day hour:minute) (EG: 2012/6/30 23:11) : ");
            fscanf(stdin, "%d/%d/%d %d:%d", &year, &month, &day, &hour, &min);
            time ( &rawtime );
            timeinfo = localtime ( &rawtime );
            timeinfo->tm_year = year;
            timeinfo->tm_mon = month;
            timeinfo->tm_mday = day;
            timeinfo->tm_hour = hour;
            timeinfo->tm_min = min;


return 0;

Recommended Answers

All 2 Replies

What format is the time in the file? Binary? Text? Other?

sorted out already.. the problem actually is the timeinfo that is a pointer not an object.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.