Understanding the Date Output in C Language

Asked 1 years ago, Updated 1 years ago, 241 views

I am currently working on the following issues in C language, but could someone please tell me how to correct the output to the log file in a different format from the example, and the fact that only one record can be saved and printed?

Save the results and date, time, and seconds of the operation as
The log limit should be 1000 lines (no consideration should be given to cases where the limit is exceeded)

Example) Record the following in log.txt
April 27, 2015 14:30:51, 5+6,11

Current State Output:

Fri Nov 11 10:51:27 2022
5+510.000000

Current State Code:

#include<stdio.h>
# include <time.h>

int main() {
int num1, num2;
charop;
float answer;
intr;
FILE*fp;

fp = fopen("log.txt", "w");

if(fp==NULL){
printf("File Open Failed\n";
return-1;
}

r = scanf("%d%c%d", & num1, & op, & num2);
if(r!=3){
puts("input error");
return1;
}

if(op=='+'){
answer = num1 + num2;
}
else if(op=='-'){
answer = num1-num2;
}
else if(op=='*'){
answer = num1 * num2;
}
else if(op=='/'){
answer=(float) num1/num2;
}
printf("%f\n", answer);

time_tt = time(NULL);
char*s = ctime(&t);

printf("%s",s);

fprintf(fp, "%s%d%c%d%f\n", s, num1, op, num2, answer);
fclose(fp);

return 0;

}

c

2022-11-11 21:14

1 Answers

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.