Hye i am running difftime tu different 2 time values, but unfortunately when i run on my laptop it does return values, but when i pass it to my friend the value returned is 0... and also when i run in windows the value returned also zero.. here is a part of my code:
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);
time_t rawtime, timein, timeout;
struct tm * timeinfo;
int year, month, day, hour, min;
double dif;
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);
timein = mktime(newBudget.timeinfo);
printf("Car Number : %s\n", newBudget.plat);
printf("Date & time of entry : %d/%d/%d at %d:%d\n", newBudget.timeinfo->tm_year, newBudget.timeinfo->tm_mon, newBudget.timeinfo->tm_mday, newBudget.timeinfo->tm_hour, newBudget.timeinfo->tm_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;
timeout = mktime(timeinfo);
dif = difftime(timeout, timein);
printf("Date & time out : %d/%d/%d at %d:%d\n", timeinfo->tm_year, timeinfo->tm_mon, timeinfo->tm_mday, timeinfo->tm_hour, timeinfo->tm_min);
char * weekday[] = { "Sunday", "Monday",
"Tuesday", "Wednesday",
"Thursday", "Friday", "Saturday"};
if(weekday[timeinfo->tm_wday]=="Sunday"){
total=p_time*1.00;
}
else if(weekday[timeinfo->tm_wday]=="Monday"|| "Tuesday"){
total=p_time*1.00;
}
else{
total=p_time*2.00;
}
printf("%s",weekday[timeinfo->tm_wday]);
printf("Parking time : %.2f hours \n", p_time);
printf("Total amount: Rm %.2f \n", total);
fseek(cfPtr, (p-1) * sizeof(struct budget), SEEK_SET);
fwrite(&newBudget, sizeof (struct budget), 1, cfPtr);
}
fclose(cfPtr);