Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2

Thread: File

  1. #1
    New Coder
    Join Date
    Jul 2002
    Location
    Malaysia
    Posts
    61
    Thanks
    0
    Thanked 0 Times in 0 Posts

    File

    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

  • #2
    New to the CF scene
    Join Date
    Mar 2003
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Make 'ftp' to global variable so writefile get acces to it. You have forgotten a ';' after void writefile(record customer).

    Good luck!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •