/*<mort> _ _<mort> | | | |<mort> | |_ __ _ ___ __ _| |_<mort> | __/ _` |/ _ \ / _` | __|<mort> | || (_| | (_) | (_| | |_<mort> \__\__, |\___/ \__,_|\__|<mort> __/ |<mort> |___/*/#include <stdlib.h>#include <stdio.h>#include <time.h>#include <string.h>void newacct(const char acct[5]){ FILE *stream; if ((stream = fopen(acct, "a")) == NULL) printf("Couldn't create the new file either!\n"); printf("New file for account created!\n\n"); // insert date header to new file char datestr[12]; size_t length; struct tm tim; time_t now; now = time(NULL); tim = *(localtime(&now)); if (length = strftime(datestr, sizeof(datestr), "#%Y%m%d\n", &tim) == 0) printf("something didn't work\n"); char *dsptr = datestr; // datestr pointer printf("header is %s", datestr); fputs(dsptr, stream); printf("Account file opened OK\n");}int main(){ const char acct[5]; FILE *stream; extern FILE *stdin; char header[10]; // header is header of file, trans is transaction type (+/-) /* variables for the account manipulation part */ const int bal = 27; char cur_bal[8], money[7]; const int trans = 43; char trantype[1]; // ask for an account name, corresponds to the filename (not realistic, i know. just stfu.) printf("\nEnter your Account Number: "); scanf("%5s", acct); if ((stream = fopen(acct, "r+")) == NULL) { printf("Could not open file for account %s, creating it..", acct); newacct(acct); exit(1); } // if the file has the date header (#<date here>) then print it back out fgets(header, sizeof(header), stream); printf("Date Created: %s\n", header); /* begin the text parsing */ /* get current balance, 27 bytes from SEEK_SET */ fseek(stream, bal, SEEK_SET); fgets(cur_bal, sizeof(cur_bal), stream); printf("Your current balance is %s\n", cur_bal); /* move the file pointer to the next part */ fseek(stream, trans, SEEK_SET); int c = fgetc(stream); if (c == '+') { fgets(money, sizeof(money), stream); printf("current balance is $%.2f, transaction amount is $%.2f\n", atof(cur_bal),atof(money)); printf("new balance is $%.2f\n", atof(cur_bal) + atof(money)); } fclose(stream);}