home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Shareware Overload
/
ShartewareOverload.cdr
/
busi
/
nojcb.zip
/
CB.C
next >
Wrap
Text File
|
1989-09-09
|
36KB
|
780 lines
/*----------------------------------------------------------------------------
* File: CB.C (in Turbo C 1.5)
*
* Purpose: Checkbook program for the Ratzlaff family. Reads the account
* file into a linear, singly linked list and performs all trans-
* actions in memory. Writes changes to the file.
*
* Author: Steven "Noji" Ratzlaff
*
* Date: 09 Sep 1989
*
* Note: This source code must be compiled with the compact memory model
* and should be compiled in 80286 code.
*--------------------------------------------------------------------------*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <process.h>
#include <math.h>
#include <errno.h>
#include <conio.h>
#include <ctype.h>
#include <alloc.h>
#include <dir.h>
#include <dos.h>
/*--------------------------------------------------------------------------*/
#define CB_DIR "C:\\CB\\"
#define DELIM ':'
#define MAX_LINE 90
#define LINE_LIM 38
#define MSG_LEN 50
#define MAX_PATH 40
#define INPUT_SP 20
#define CURSOR 12
#define DEC 10
#define ELEMENTS 4
#define TRUE 1
#define FALSE 0
/*------------ Key Values for get_char() -----------------------------------*/
#define BS 8
#define RET 13
#define ESC 27
#define SP 32
#define F1 187
#define F2 188
#define F3 189
#define F4 190
#define F5 191
#define F6 192
#define F7 193
#define F8 194
#define F9 195
#define F10 196
#define HOME 199
#define UP 200
#define PGUP 201
#define LEFT 203
#define RGT 205
#define END 207
#define DN 208
#define PGDN 209
#define DEL 211
/*--------------------------------------------------------------------------*/
int before_date(), /* determines the place of a date */
index = 0, /* index number of the last record */
get_char(), /* gets a keyboard character */
read_string(); /* reads a string from the keyboard */
char beg_bal[INPUT_SP], /* beginning account balance */
last_check[INPUT_SP], /* the last check number */
*prompt; /* the prompt from the environment */
void transact(), /* calls all transaction routines */
balance(), /* balances the checkbook */
clear_line(), /* clears to the end of the line */
date_format(), /* formats the date to standard form */
directory(), /* displays the account directory */
enter_data(), /* enters data from user to the list */
get_todays_date(), /* grabs and formats today's date */
get_cursor(), /* retrieves the cursor position */
increment_date(), /* increments the date string */
instructions(), /* displays program instructions */
list(), /* displays the list contents */
make_change(), /* allows user to change the list */
num_format(), /* formats a floating point string */
outfile(), /* outputs the checkbook data */
pause(), /* Press <Space> to continue */
repeat_entry(), /* prompts and enters data */
save(), /* saves the list to a file */
set_cursor(), /* sets the cursor position */
shell_out(); /* shells out to DOS */
char *Version = "CB 1.0 (C) Sep 1989 by Steven \"Noji\" Ratzlaff";
#include "cbmain.inc"
/*----------------------------------------------------------------------------
* transact(): Transacts whatever business is needed by calling all other
* routines pertinent to the requests.
*--------------------------------------------------------------------------*/
void
transact(fname, yn)
char *fname; /* filename of the account file */
int yn; /* create a new account? */
{
FILE *fp; /* pointer to the account file */
struct Record
*rec; /* pointer to a record */
char line[MAX_LINE]; /* input line from the file */
int sel = 0, /* transaction selection */
data_entered = FALSE, /* has data been entered? */
save_executed = FALSE, /* has the new data been saved? */
i = 0; /* arbitrary counter */
double total; /* total from adding machine */
/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
if (yn != 'y') /* if no new file is to be created */
{
fp = fopen(fname, "r"); /* open the file */
while (fgets(line, MAX_LINE, fp)) /* read the contents */
{
rec = (struct Record *) malloc((unsigned) sizeof(struct Record));
sscanf(line, "%[^:]:%[^:]:%[^:]:%[^:]:%[^:]:",
rec->check, rec->date, rec->amt, rec->pur, rec->bal);
rec->ind = ++index;
rec->next = NULL;
if (head == NULL)
head = rec;
else
cur->next = rec;
cur = tail = rec;
if (atoi(rec->check) > 100) /* if we have a valid check number */
strcpy(last_check, rec->check);
}
fclose(fp); /* close the file */
} /* end of if (yn != 'y') */
/*------------------------------------*
* Main Menu Loop *
*------------------------------------*/
do {
clrscr(); /* clear the screen */
sel = 0;
cur = tail;
printf("%40s\n\n", "Checkbook Main Menu");
printf("Select an action: \n\n"
" E>nter a transaction L>ist the account\n"
" D>irectory of accounts M>ake a change\n"
" A>dding machine I>nstructions\n"
" B>alance the account O>utput to a file\n"
" C>ommand Shell R>estricted\n"
" S>ave Q>uit\n");
gotoxy(20, 3);
while (sel!='e' && sel!='d' && sel!='l' && sel!='a' && sel!='m' &&
sel!='b' && sel!='o' && sel!='i' && sel!='s' && sel!='q' &&
sel!='c' && sel!=ESC)
sel = tolower(getch());
gotoxy(1, CURSOR);
switch (sel)
{
case 'e' : enter_data(); /* enter data */
data_entered = TRUE;
save_executed = FALSE;
break;
case 'd' : directory(TRUE); /* directory */
break;
case 'l' : list(); /* list the data */
break;
case 'a' : printf("Adding machine [enter alone to quit]:\n\n");
repeat_entry(line, &total);
printf(" Total: %9.2f\n", total);
pause();
break;
case 'm' : make_change(); /* make a change */
data_entered = TRUE;
save_executed = FALSE;
break;
case 'c' : shell_out(); /* shell to DOS */
break;
case 'b' : balance(); /* balance acct */
break;
case 'o' : outfile(); /* output data */
break;
case 'i' : instructions(); /* instructions */
break;
case 's' : save(fname); /* save entries */
save_executed = TRUE;
break;
case 'q' :
case ESC : if (data_entered && !save_executed && cur != NULL)
{
printf(" Save changes and new entries? ");
while (i != 'y' && i != 'n')
i = tolower(getch());
if (i == 'y')
save(fname);
}
default : break;
} /* end of switch (sel) */
} while (sel != ESC && sel != 'q'); /* end of do { ... */
} /* end of transact() */
/*----------------------------------------------------------------------------
* balance(): Aids the user in balancing the checkbook account.
*--------------------------------------------------------------------------*/
void
balance()
{
char endbal[INPUT_SP], /* ending bank balance */
odbal[INPUT_SP], /* ending overdraft balance */
c_checks[INPUT_SP], /* outstanding checks */
c_deps[INPUT_SP], /* " deposits */
c_ints[INPUT_SP], /* " interests */
c_charges[INPUT_SP], /* " other charges */
chk_num[INPUT_SP], /* beginning check number */
overunder[INPUT_SP]; /* over or under? */
int yn = 0; /* input response */
double end_bal, /* ending bank balance */
od_bal, /* ending overdraft balance */
checks, /* outstanding checks */
deposits, /* " deposits */
ints, /* " interests */
charges, /* " other charges */
last, /* the amount of the last balance */
total = 0.0, /* total after all calculations */
diff; /* difference between bank and user */
/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
printf(" Balance the account? [ <Y>es <N>o <I>nstructions ] ");
while (yn != 'y' && yn != 'n' && yn != 'i' && yn != ESC)
yn = tolower(getch());
if (yn == 'y' || yn == 'i')
{
if (yn == 'y') /* ready to balance the account */
{
yn = 0;
gotoxy(1, wherey());
printf(" Total a continuous range of outstanding checks? ");
gotoxy(52, wherey());
while (yn != 'y' && yn != 'n')
yn = tolower(getch());
gotoxy(1, wherey());
if (yn == 'y')
{
yn = 0;
printf(" Enter the starting check number: ");
gotoxy(37, wherey());
gets(chk_num);
for (cur = head; cur != NULL && strcmp(chk_num, cur->check);
cur = cur->next);
for (total = 0.0; cur != NULL; cur = cur->next)
if (atoi(cur->check) > 100)
total += atof(cur->amt);
}
printf(" Enter the ending bank statement balance: ");
gotoxy(45, wherey());
gets(endbal);
end_bal = atof(endbal);
printf(" Enter the ending overdraft or Visa debit balance: ");
gets(odbal);
od_bal = atof(odbal);
printf(" Enter %s checks and Visa debits:\n\n",
(yn == 'y' ? "other outstanding" : "outstanding"));
repeat_entry(c_checks, &checks);
checks += total;
printf(" Enter outstanding deposits:\n\n");
repeat_entry(c_deps, &deposits);
printf(" Enter interests and dividends:\n\n");
repeat_entry(c_ints, &ints);
printf(" Enter other charges:\n\n");
repeat_entry(c_charges, &charges);
last = atof(tail->bal);
total = end_bal - od_bal - checks + deposits - ints + charges;
diff = fabs(total - last); /* find the difference */
if (diff < 0.001) /* C floating point oddity */
printf("\n %c%c%c Good job...your account balanced. %c%c%c\n\n",
2, 2, 2, 2, 2, 2);
else
{
if (last > total) /* checkbook is over */
strcpy(overunder, "over");
else /* checkbook is under */
strcpy(overunder, "under");
printf("\n Your account is %s by %-8.2f\n\n", overunder, diff);
printf("%s%8.2f\n%s%8.2f\n\n",
" Account balance: ", last,
" Bank balance: ", total);
}
} /* end of if (yn == 'y') */
else /* need instructions */
{
clrscr();
printf(" Instructions for Balancing your Account\n\n"
"Write down:\n"
" 1. The ending bank balance\n"
" 2. The ending overdraft or Visa debit total\n"
" 3. Outstanding checks and Visa debits\n"
" 4. Outstanding deposits\n"
" 5. The overdraft or Visa debit finance charges\n"
" 6. Excess draft and other charges\n"
" 7. Loan payments not yet entered\n"
" 8. Overdraft or Visa debit payments made by cash\n"
" 9. Interests and dividends\n\n"
"Enter interests, dividends, and overdraft cash payments under\n"
" 'Interests'.\n\n"
"Enter the overdraft finance charges, excess draft charges, unentered\n"
" loan payments, and other charges under 'Other Charges'.\n\n");
printf("Enter the following formats into the account:\n"
" The Visa cash payments as DEP The loan payments as UCC\n"
" The Visa finance charges as VIS Interests and dividends as DEP\n"
" The excess draft charge as XS All other charges as OTH\n");
} /* end of else of if (yn == 'y') */
pause();
} /* end of if (yn == 'y' || ... */
} /* end of balance() */
/*----------------------------------------------------------------------------
* date_format(): Formats the string date to the standard format set by this
* program.
*--------------------------------------------------------------------------*/
void
date_format(dt)
char *dt; /* input date string */
{
char c_day[INPUT_SP], /* the day string */
c_month[INPUT_SP], /* the month string */
c_year[INPUT_SP]; /* the year string */
int len, /* length of the string */
first = 0, /* position of the first dash */
sec = 0, /* " " " second " */
n_day, /* day number */
n_month, /* month number */
i; /* arbitrary counter */
/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
if (dt[0] == '\0')
get_todays_date(dt);
len = (int) strlen(dt);
if (len != 9)
{
for (i = 0; i < len && dt[first] != '-' && dt[first] != '/'; i++)
if (dt[i] == '-' || dt[i] == '/') /* find the first '-' */
first = i;
for (i = 0; i < len; i++)
if (dt[i] == '-' || dt[i] == '/') /* find the last '-' */
sec = i;
strcpy(c_day, dt);
if (first == sec) /* if only one '-' */
{
get_todays_date(c_year); /* provide year */
c_year[0] = c_year[7];
c_year[1] = c_year[8];
c_year[2] = '\0';
if (isdigit(dt[0])) /* get the month */
{
dt[first] = '\0';
n_month = atoi(dt);
}
else
{
dt[3] = '\0';
strlwr(dt);
for (i = 1; i < 13; i++)
if (strcmp(dt, strlwr(month[i])) == 0)
n_month = i;
} /* end of if (isdigit(dt[0])) */
strcpy(c_month, month[n_month]);
c_day[0] = c_day[first + 1];
c_day[1] = c_day[first + 2];
c_day[2] = '\0';
} /* end of if (first == sec) */
else
if (dt[first] == '-')
sscanf(dt, "%[^-]-%[^-]-%[^-]", c_day, c_month, c_year);
else
sscanf(dt, "%[^/]/%[^/]/%[^/]", c_day, c_month, c_year);
n_day = atoi(c_day);
if (n_day < DEC && c_day[0] != '0') /* leading zeroes in day */
{
c_day[1] = c_day[0];
c_day[0] = '0';
c_day[2] = '\0';
}
strcpy(dt, c_day);
strcat(dt, "-");
strcat(dt, c_month);
strcat(dt, "-");
strcat(dt, c_year);
} /* end of if (len != 9) */
strlwr(dt);
dt[3] -= 32;
} /* end of date_format() */
/*----------------------------------------------------------------------------
* enter_data(): Prompts user for input and enters the data into a structure
* pointed at by cur.
*--------------------------------------------------------------------------*/
void
enter_data()
{
struct Record
*rec; /* pointer to a record */
int ind, /* index into the array */
xcur, /* current x position */
ycur, /* " y " */
c = 0; /* delimiter of the input string */
char todays_date[INPUT_SP]; /* a copy of today's date */
double temp; /* temporary floaing point storage */
/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
printf(" Transaction Entry");
while (c != ESC)
{
rec = (struct Record *) malloc((unsigned) sizeof(struct Record));
*rec->check = *rec->date = *rec->amt = *rec->pur = *rec->bal = '\0';
get_todays_date(todays_date);
if (cur != NULL)
{
printf(" -- Last Entry: \n\n%s%s\n\n",
"Ind Item Date Amount ",
"Purpose Balance");
printf("%3d %4s %9s %7s %-38s %8s\n\n",
cur->ind, cur->check, cur->date, cur->amt, cur->pur, cur->bal);
strcpy(input[1].var, cur->date);
}
else
{
printf(":\n\n");
strcpy(input[1].var, todays_date);
}
input[0].var[0] = input[2].var[0] = input[3].var[0] = '\0';
for (ind = 0; ind < ELEMENTS && c != ESC; ind++)
{
printf(" %s ", input[ind].msg); /* print out the prompt */
get_cursor(&xcur, &ycur);
if (ind == 0 && last_check[0]) /* find the next check # */
itoa(atoi(last_check)+1, input[ind].var, 10);
if (ind == 0 || ind == 1)
printf(input[ind].var);
if (ind == 1)
do {
c = read_string(input[ind].var);
switch (c)
{
case END : if (strcmp(input[ind].var, cur->date) == 0 ||
cur == NULL)
strcpy(input[ind].var, todays_date);
else
strcpy(input[ind].var, cur->date);
break;
case UP :
case DN :
case PGUP :
case PGDN : increment_date(input[ind].var, c);
break;
default : break;
} /* end of switch (c) */
set_cursor(xcur, ycur);
printf(input[ind].var);
} while (c==END || c==UP || c==DN || c==PGUP || c==PGDN);
else
c = read_string(input[ind].var); /* read in the string */
set_cursor(xcur, ycur);
printf("%s\n", input[ind].var); /* print the string out */
} /* end of for (ind = 0... */
if (c != ESC)
{
strupr(input[0].var);
strcpy(rec->check, input[0].var);
strcpy(rec->date, input[1].var);
strcpy(rec->amt, input[2].var);
strcpy(rec->pur, input[3].var);
date_format(rec->date);
num_format(rec->amt);
printf("\n %4s %9s %7s %-38s\n\n",
rec->check, rec->date, rec->amt, rec->pur);
get_cursor(&xcur, &ycur);
printf(" Is this correct? ");
while (c != 'y' && c != 'n')
c = tolower(getch());
set_cursor(xcur, ycur);
if (c == 'y')
{
rec->ind = ++index;
if (head == NULL)
if (stricmp(rec->check,"DEP") == 0)
temp = atof(beg_bal) + atof(rec->amt);
else
temp = atof(beg_bal) - atof(rec->amt);
else
if (stricmp(rec->check,"DEP") == 0)
temp = atof(cur->bal) + atof(rec->amt);
else
temp = atof(cur->bal) - atof(rec->amt);
gcvt(temp, 8, rec->bal);
num_format(rec->bal);
rec->next = NULL;
if (head == NULL)
head = rec;
else
cur->next = rec;
cur = tail = rec;
if (atoi(rec->check) > 100) /* if we have a valid check number */
strcpy(last_check, rec->check);
} /* end of if (c == 'y') */
} /* end of if (c != ESC) */
} /* end of while (c != ESC) */
} /* end of enter_data() */
/*----------------------------------------------------------------------------
* list(): Displays the contents of the list.
*--------------------------------------------------------------------------*/
void
list()
{
int c = 0, /* primary selection */
d = 0, /* secondary selection */
ind, /* index into the array */
proceed = TRUE, /* the scrolling may proceed */
lines = 0; /* lines appearing on the screen */
double total = 0.0; /* total of listed amounts */
char ch[INPUT_SP], /* buffer for the check number */
dt[INPUT_SP], /* " " " date */
am[INPUT_SP], /* " " " amount */
pu[MSG_LEN]; /* " " " purpose */
/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
printf(" Listing by\n\n%s",
" A>ll transactions\n"
" S>pecific items\n"
" D>ate beginning\n");
gotoxy(15, CURSOR);
while (c != 'a' && c != 's' && c != 'd' && c != ESC)
c = tolower(getch());
if (c != ESC)
{
gotoxy(1, CURSOR + 6);
cur = head;
if (c == 's')
{
printf(" Enter the items to list:\n\n%s",
" Check / Item:\n"
" Date:\n"
" Amount:\n"
" Purpose:\n");
do { /* all can't be empty */
for (ind = 0; ind < ELEMENTS; ind++)
{
gotoxy(23, CURSOR + ind + 8);
input[ind].var[0] = '\0';
gets(input[ind].var);
strlwr(input[ind].var);
}
} while (!input[0].var[0] && !input[1].var[0] &&
!input[2].var[0] && !input[3].var[0]);
} /* end of if (c == 's') */
else
if (c == 'd')
{
printf(" Enter the starting date: ");
gets(input[1].var);
date_format(input[1].var);
strcpy(dt, cur->date);
while (cur != NULL && before_date(dt, input[1].var))
{
cur = cur->next;
strcpy(dt, cur->date);
}
} /* end of if (c == 'd') */
printf("\n%s%s\n\n",
"Ind Item Date Amount ",
"Purpose Balance");
while (cur != NULL && d != ESC && d != 'q')
{
switch (c)
{
case 'a' :
case 'd' : printf("%3d %4s %9s %7s %-38s %8s\n",
cur->ind, cur->check, cur->date,
cur->amt, cur->pur, cur->bal);
lines++;
break;
case 's' : strcpy(ch, cur->check);
strlwr(ch);
strcpy(dt, cur->date);
strlwr(dt);
strcpy(am, cur->amt);
strlwr(am);
strcpy(pu, cur->pur);
strlwr(pu);
if (strstr(ch, input[0].var) && strstr(dt, input[1].var) &&
strstr(am, input[2].var) && strstr(pu, input[3].var))
{
printf("%3d %4s %9s %7s %-38s %8s\n",
cur->ind, cur->check, cur->date,
cur->amt, cur->pur, cur->bal);
lines++;
proceed = TRUE;
total += atof(cur->amt);
}
else
proceed = FALSE;
default : break;
} /* end of switch (c) */
if ((lines >= 22 || d == '\r') && proceed)
{
lines = 0;
printf("--- <Space> = Continue | <Enter> = Step | <Esc> = Quit ---");
d = tolower(getch());
gotoxy(1, wherey());
printf(" ");
gotoxy(1, wherey());
if (d == SP)
printf("\n%s%s\n\n",
"Ind Item Date Amount ",
"Purpose Balance");
}
cur = cur->next;
} /* end of while (cur != NULL ...) */
if (c == 's')
printf("\n %9.2f Total\n", total);
pause();
} /* end of if (c != ESC) */
} /* end of list() */
/*----------------------------------------------------------------------------
* make_change(): Prompts the user for changes to be made on the list data
* and incorporates those changes.
*--------------------------------------------------------------------------*/
void
make_change()
{
char c_ind[INPUT_SP], /* input index number to search for */
old_item[INPUT_SP], /* old item string */
old_amt[INPUT_SP]; /* old amount string */
double temp1, temp2; /* temporary double values */
int item_changed = FALSE, /* the item was changed */
amt_changed = FALSE, /* the amount changed */
xcur, /* current x position */
ycur, /* " y " */
c = 0, /* returned input value */
ind = 0, /* index counter */
rv = 0; /* return value from function */
/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
c_ind[0] = '\0';
printf(" Enter index number of item to change [<Esc> to abort]: ");
rv = read_string(c_ind);
printf("%s\n\n", c_ind);
if (rv != ESC && rv != UP && rv != DN && rv != PGUP && rv != PGDN)
{
rv = atoi(c_ind);
for (cur = head; cur != NULL && cur->ind != rv; cur = cur->next)
;
if (cur != NULL)
{
gotoxy(1, CURSOR);
printf("%s%s\n\n",
"Ind Item Date Amount ",
"Purpose Balance");
printf("%3d %4s %9s %7s %-38s %8s\n\n",
cur->ind, cur->check, cur->date, cur->amt, cur->pur, cur->bal);
printf(" Change this record? ");
while (c != 'y' && c != 'n')
c = tolower(getch());
if (c == 'y')
{
c = 0;
strcpy(old_item, cur->check);
strcpy(old_amt, cur->amt);
strcpy(input[0].var, cur->check);
strcpy(input[1].var, cur->date);
strcpy(input[2].var, cur->amt);
strcpy(input[3].var, cur->pur);
gotoxy(1, CURSOR + 4);
printf(" Enter the changes: \n\n");
for (ind = 0; ind < ELEMENTS && rv != ESC; ind++)
{
printf(" %s ", input[ind].msg); /* print out the prompt */
get_cursor(&xcur, &ycur);
printf(input[ind].var);
if (ind == 1)
do {
rv = read_string(input[ind].var);
if (rv == UP || rv == DN || rv == PGUP || rv == PGDN)
increment_date(input[ind].var, rv);
set_cursor(xcur, ycur);
printf(input[ind].var);
} while (rv==UP || rv==DN || rv==PGUP || rv==PGDN);
else
rv = read_string(input[ind].var); /* read in the string */
set_cursor(xcur, ycur);
printf("%s\n", input[ind].var); /* print the string out */
} /* end of for (ind = 0... */
if (rv != ESC)
{
strupr(input[0].var);
date_format(input[1].var);
num_format(input[2].var);
printf("\n %4s %9s %7s %-38s\n\n",
input[0].var, input[1].var, input[2].var, input[3].var);
printf(" Is this correct? ");
while (c != 'y' && c != 'n')
c = tolower(getch());
if (c == 'y')
{
item_changed = strcmp(input[0].var, cur->check);
amt_changed = strcmp(input[2].var, cur->amt);
strcpy(cur->check, input[0].var);
strcpy(cur->date, input[1].var);
strcpy(cur->amt, input[2].var);
strcpy(cur->pur, input[3].var);
if (item_changed)
{
if ((stricmp(old_item, "DEP") == 0 &&
stricmp(input[0].var, "DEP") != 0) ||
(stricmp(old_item, "DEP") != 0 &&
stricmp(input[0].var, "DEP") == 0))
{
temp1 = atof(input[2].var) + atof(old_amt);
while (cur != NULL)
{
if (stricmp(old_item, "DEP") == 0 &&
stricmp(input[0].var, "DEP") != 0)
temp2 = atof(cur->bal) - temp1;
else
temp2 = atof(cur->bal) + temp1;
gcvt(temp2, 8, cur->bal);
num_format(cur->bal);
cur = cur->next;
} /* end of while (cur != NULL) */
} /* end of if (stricmp(...)) */
} /* end of if (item_changed) */
else
if (amt_changed)
{
if (stricmp(old_item, "DEP") == 0)
temp1 = atof(input[2].var) - atof(old_amt);
else
temp1 = atof(old_amt) - atof(input[2].var);
while (cur != NULL)
{
temp2 = atof(cur->bal) + temp1;
gcvt(temp2, 8, cur->bal);
num_format(cur->bal);
cur = cur->next;
}
} /* end of if (amt_changed) */
} /* end of if (c == 'y') */
} /* end of if (rv != ESC) */
} /* end of if (c == 'y') */
} /* end of if (cur != NULL) */
else
{
printf(" Index number %d does not exist\n", rv);
pause();
} /* end of else of if (cur != NULL) */
} /* end of if (rv != ESC ...) */
} /* end of make_change() */
/*----------------------------------------------------------------------------
* outfile(): Outputs the list data to a file.
*--------------------------------------------------------------------------*/
void
outfile()
{
FILE *fp; /* pointer to the output file */
char fname[MSG_LEN]; /* name of file to write to */
int rv = 0; /* return value from function */
/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
fname[0] = '\0';
printf(" Enter the filename to store the account [<Esc> to abort]: ");
rv = read_string(fname);
printf("%s\n\n", fname);
if (rv != ESC && rv != UP && rv != DN && rv != PGUP && rv != PGDN)
{
if (fp = fopen(fname, "w"))
{
fprintf(fp, "%s%s\n\n",
"Ind Item Date Amount ",
"Purpose Balance");
for (cur = head; cur != NULL; cur = cur->next)
fprintf(fp, "%3d %4s %9s %7s %-38s %8s\n",
cur->ind, cur->check, cur->date, cur->amt,
cur->pur, cur->bal);
fclose(fp);
} /* end of if (fp = fopen(fname...)) */
else
{
printf(" *** File '%s' could not be written to\n", fname);
pause();
}
} /* end of if (rv != ESC ...) */
} /* end of outfile() */
/*----------------------------------------------------------------------------
* End of CB.C
*--------------------------------------------------------------------------*/