Xiang
03-30-2003, 03:15 PM
Dear sir,
Refers to the below coding. Do you know where is my mistake, as my program has occur error message.
/* create a data file containing customer records */
#include <stdio.h>
#include <conio.h>
#include <string.h>
#define TRUE 1
typedef struct
{
int month;
int day;
int year;
} date;
typedef struct
{
char name[80];
char street[80];
char city[80];
int acct_no; /* (positive integer) */
char acct_type; /* C (current), O (overdue), or D (delinquent) */
float oldbalance; /* (nonnegative quantity) */
float newbalance; /* (nonnegative quantity) */
float payment; /* (nonnegative quantity) */
date lastpayment;
} record;
record readscreen(record customer); /* function prototype */
void writefile(record customer) /* function prototype */
main()
{
FILE *fpt; /* pointer to predefined structure FILE */
int flag = TRUE; /* variable declaration */
record customer; /* structure variable declaration */
clrscr();
/* open a neew data file for writing only */
fpt = fopen("records.dat", "w");
/* enter date an assign initial values */
printf("CUSTOMER BILLING SYSTEM - INITIALIZATION\n\n");
printf("Please enter today\'s date (mm/dd/yyyy); ");
scanf("%d/%d/%d", &customer.lastpayment.month,
&customer.lastpayment.day,
&customer.lastpayment.year);
customer.newbalance = 0;
customer.payment = 0;
customer.acct_type = 'C';
/* main loop */
while (flag)
{
/* enter cuatomer's name and write to data file */
printf ("\nName (enter \'END\' when finished); ");
scanf ("%[^\n]", customer.name);
fprintf(fpt, "\n%s\n", customer.name);
/* test for stopping condition */
if (strcmp(customer.name, "END") == 0)
break;
customer = readscreen(customer);
writefile(customer);
}
fclose(fpt);
}
record readscreen(record customer)/* read remaining data */
{
printf("Street: ");
scanf("%[^\n]", customer.street);
printf("City: ");
scanf(" %[^\n]", customer.city);
printf("Account number: ");
scanf("%d", &customer.acct_no);
printf("Current balance: ");
scanf("%f", &customer.oldbalance);
return(customer);
}
void writefile(record customer)/* write remaining data to a data file */
{
fprintf(fpt, "%s\n", customer.street);
fprintf(fpt, "%s\n", customer.city);
fprintf(fpt, "%d\n", customer.acct_no);
fprintf(fpt, "%c\n", customer.acct_type);
fprintf(fpt, "%.2f\n", customer.oldbalance);
fprintf(fpt, "%.2f\n", customer.newbalance);
fprintf(fpt, "%.2f\n", customer.payment);
fprintf(fpt, "%d/%d/%d\n", customer.lastpayment.month,
customer.lastpayment.day,
customer.lastpayment.year);
return;
}
Thanks
Xiang
Refers to the below coding. Do you know where is my mistake, as my program has occur error message.
/* create a data file containing customer records */
#include <stdio.h>
#include <conio.h>
#include <string.h>
#define TRUE 1
typedef struct
{
int month;
int day;
int year;
} date;
typedef struct
{
char name[80];
char street[80];
char city[80];
int acct_no; /* (positive integer) */
char acct_type; /* C (current), O (overdue), or D (delinquent) */
float oldbalance; /* (nonnegative quantity) */
float newbalance; /* (nonnegative quantity) */
float payment; /* (nonnegative quantity) */
date lastpayment;
} record;
record readscreen(record customer); /* function prototype */
void writefile(record customer) /* function prototype */
main()
{
FILE *fpt; /* pointer to predefined structure FILE */
int flag = TRUE; /* variable declaration */
record customer; /* structure variable declaration */
clrscr();
/* open a neew data file for writing only */
fpt = fopen("records.dat", "w");
/* enter date an assign initial values */
printf("CUSTOMER BILLING SYSTEM - INITIALIZATION\n\n");
printf("Please enter today\'s date (mm/dd/yyyy); ");
scanf("%d/%d/%d", &customer.lastpayment.month,
&customer.lastpayment.day,
&customer.lastpayment.year);
customer.newbalance = 0;
customer.payment = 0;
customer.acct_type = 'C';
/* main loop */
while (flag)
{
/* enter cuatomer's name and write to data file */
printf ("\nName (enter \'END\' when finished); ");
scanf ("%[^\n]", customer.name);
fprintf(fpt, "\n%s\n", customer.name);
/* test for stopping condition */
if (strcmp(customer.name, "END") == 0)
break;
customer = readscreen(customer);
writefile(customer);
}
fclose(fpt);
}
record readscreen(record customer)/* read remaining data */
{
printf("Street: ");
scanf("%[^\n]", customer.street);
printf("City: ");
scanf(" %[^\n]", customer.city);
printf("Account number: ");
scanf("%d", &customer.acct_no);
printf("Current balance: ");
scanf("%f", &customer.oldbalance);
return(customer);
}
void writefile(record customer)/* write remaining data to a data file */
{
fprintf(fpt, "%s\n", customer.street);
fprintf(fpt, "%s\n", customer.city);
fprintf(fpt, "%d\n", customer.acct_no);
fprintf(fpt, "%c\n", customer.acct_type);
fprintf(fpt, "%.2f\n", customer.oldbalance);
fprintf(fpt, "%.2f\n", customer.newbalance);
fprintf(fpt, "%.2f\n", customer.payment);
fprintf(fpt, "%d/%d/%d\n", customer.lastpayment.month,
customer.lastpayment.day,
customer.lastpayment.year);
return;
}
Thanks
Xiang