We're a community of 1076K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,075,878 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

Time problema

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");}
        else{
        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;
            mktime(timeinfo);



        fclose(cfPtr);
}



return 0;
}
2
Contributors
2
Replies
1 Day
Discussion Span
11 Months Ago
Last Updated
3
Views
Question
Answered
wan632
Newbie Poster
4 posts since May 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0

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

WaltP
Posting Sage w/ dash of thyme
Team Colleague
11,404 posts since May 2006
Reputation Points: 3,421
Solved Threads: 1,055
Skill Endorsements: 37

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

wan632
Newbie Poster
4 posts since May 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0
Question Answered as of 11 Months Ago by WaltP

This question has already been solved: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page rendered in 0.0852 seconds using 2.68MB