File Handling and Error Handling

I want a crossover with my files wondering can anyone help me with , Loan,Video, and customer file loan will hold loan no, video no, member no,etc, video will hold video no,video name, durtion, cert etc, member will hold member no, name, address etc. how can I link member and loan, video and loan with error handling(THE BIG PROBLEM). Any help would be great thanks.

Comments

  • : I want a crossover with my files wondering can anyone help me with , Loan,Video, and customer file loan will hold loan no, video no, member no,etc, video will hold video no,video name, durtion, cert etc, member will hold member no, name, address etc. how can I link member and loan, video and loan with error handling(THE BIG PROBLEM). Any help would be great thanks.
    :

    You need to define the data structure so that each has a common relational element. In this case a customer number/name should probably be the common element between your data structures.
  • : : I want a crossover with my files wondering can anyone help me with , Loan,Video, and customer file loan will hold loan no, video no, member no,etc, video will hold video no,video name, durtion, cert etc, member will hold member no, name, address etc. how can I link member and loan, video and loan with error handling(THE BIG PROBLEM). Any help would be great thanks.
    : :
    :
    : You need to define the data structure so that each has a common relational element. In this case a customer number/name should probably be the common element between your data structures.
    :
    yeah trhanks yeah i know this but how do i actually code it
  • : : : I want a crossover with my files wondering can anyone help me with , Loan,Video, and customer file loan will hold loan no, video no, member no,etc, video will hold video no,video name, durtion, cert etc, member will hold member no, name, address etc. how can I link member and loan, video and loan with error handling(THE BIG PROBLEM). Any help would be great thanks.
    : : :
    : :
    : : You need to define the data structure so that each has a common relational element. In this case a customer number/name should probably be the common element between your data structures.
    : :
    : yeah trhanks yeah i know this but how do i actually code it
    :

    two of the structs might be coded like this, with member_number being the unique key.

    [code]
    struct customer{
    char name[20];
    char member_number[20];
    bool has_bad_breath;
    }

    struct loan{
    char member_number[20];
    float loan_amount;
    float interest_rate;
    float late_fee;
    float amount_owed;
    char next_payment[20];
    }
    [/code]
  • : : : : I want a crossover with my files wondering can anyone help me with , Loan,Video, and customer file loan will hold loan no, video no, member no,etc, video will hold video no,video name, durtion, cert etc, member will hold member no, name, address etc. how can I link member and loan, video and loan with error handling(THE BIG PROBLEM). Any help would be great thanks.
    : : : :
    : : :
    : : : You need to define the data structure so that each has a common relational element. In this case a customer number/name should probably be the common element between your data structures.
    : : :
    : : yeah trhanks yeah i know this but how do i actually code it
    : :
    :
    : two of the structs might be coded like this, with member_number being the unique key.
    :
    : [code]
    : struct customer{
    : char name[20];
    : char member_number[20];
    : bool has_bad_breath;
    : }
    :
    : struct loan{
    : char member_number[20];
    : float loan_amount;
    : float interest_rate;
    : float late_fee;
    : float amount_owed;
    : char next_payment[20];
    : }
    : [/code]
    : tahnks but I know this I'm lookinf for how the code is writen when its carefgully klnitted into with the file handling

  • : : tahnks but I know this I'm lookinf for how the code is writen when its carefgully klnitted into with the file handling

    I wrote this a while back. I don't recall testing these functions to any extent as delivery dates for the machine forced me to trim features - so I can't gaurantee they are 100% bug free.

    This feature was intended to assist the owner of the machine in tracking the machine operating time by customer name. Customer name is the common element in the other linked lists in the system. It should give you an idea how to work with lists and files. All you would have to do is create the other lists and files based on this model.

    Keep in mind you gotta be mighty brave when you use source code written by me. :-)

    [code]
    struct customer{
    char name[21];
    long tipsdone;
    long sawsdone;
    float time;
    struct customer *next;
    struct customer *previous;
    struct customer *head;
    struct customer *tail;
    };

    void add_customer( void ){
    struct customer *next;
    FILE *customer_file;
    char *new_customer = NULL;
    char myname[21] = "";
    struct customer current_customer;
    size_t length;
    size_t n = 20;
    size_t io_size;
    int duplicate = 0;
    int i = 0;

    io_size = sizeof( customer );
    if( customer_file = fopen( "customer.wmt","rb" ) ){
    printf("
    file is opened
    ");
    while( strcmp( myname , "EXIT") != 0 ){
    printf("
    Please input the customer name :");
    scanf( "%s" , myname );
    if( length = strlen( myname ) <= 20 ){
    if( strcmp( myname , "EXIT" ) != 0 ){
    strncpy( current_customer.name , myname, n );
    next = (struct customer *) malloc( io_size );
    rewind( customer_file );

    while( fread( next, io_size, 1, customer_file ) == 1 ){
    if( strcmp( next->name , current_customer.name ) == 0 )
    duplicate = 1;
    }
    free( next );
    if( duplicate != 1 ){
    fclose( customer_file );
    customer_file = fopen( "customer.wmt","ab" );
    current_customer.tipsdone = 0;
    current_customer.sawsdone = 0;
    current_customer.time = 0;
    fwrite( &current_customer, io_size, 1, customer_file );
    fclose( customer_file);
    customer_file = fopen( "customer.wmt","rb" );
    }
    else{
    printf("
    Duplicate name.");
    printf("
    Name not added to file.
    ");
    duplicate = 0;
    rewind( customer_file );
    }
    }


    }
    else{
    printf("
    Must be less than 20 characters.");
    }
    }
    }
    else{
    printf("
    Could not open file.");
    }

    fclose( customer_file );
    }



    struct customer *get_customers( void ){

    FILE *customer_file;
    size_t io_size;

    struct customer current_customer;
    struct customer *customer_pointer;
    struct customer *temp_customer_pointer;
    struct customer *customer_start = NULL;

    io_size = sizeof( customer );

    if( customer_file = fopen( "customer.wmt","rb" ) ){
    customer_pointer = (struct customer *) malloc( io_size );
    temp_customer_pointer = customer_pointer;
    while( fread( customer_pointer, io_size, 1, customer_file ) != 0 ){

    if( customer_start == NULL ){
    customer_start = customer_pointer;
    customer_pointer->head = customer_pointer;
    customer_pointer->previous = NULL;
    customer_pointer->tail = customer_pointer;
    customer_pointer->next = NULL;
    }
    else{
    temp_customer_pointer->next = customer_pointer;
    temp_customer_pointer->tail = customer_pointer;
    customer_pointer->head = customer_start;
    customer_pointer->previous = temp_customer_pointer;
    customer_pointer->tail = customer_pointer;
    customer_pointer->next = NULL;
    }

    temp_customer_pointer = customer_pointer;
    customer_pointer = (struct customer *) malloc( io_size );

    }
    fclose( customer_file );
    }
    else{
    if( customer_file = fopen( "customer.wmt","wb") ){

    puts("Customer file not found.");
    puts("Please input customer name ");

    fflush(stdin);

    gets(current_customer.name);

    current_customer.tipsdone = 0;
    current_customer.sawsdone = 0;
    current_customer.time = 0;

    fwrite( &current_customer, io_size, 1, customer_file );
    fclose( customer_file );
    printf("
    Customer file was created");
    return NULL;

    }
    else{
    printf("
    Could not create file.");
    return NULL;
    }
    }
    return customer_start;
    }


    [/code]
  • : : : tahnks but I know this I'm lookinf for how the code is writen when its carefgully klnitted into with the file handling
    :
    : I wrote this a while back. I don't recall testing these functions to any extent as delivery dates for the machine forced me to trim features - so I can't gaurantee they are 100% bug free.
    :
    : This feature was intended to assist the owner of the machine in tracking the machine operating time by customer name. Customer name is the common element in the other linked lists in the system. It should give you an idea how to work with lists and files. All you would have to do is create the other lists and files based on this model.
    :
    : Keep in mind you gotta be mighty brave when you use source code written by me. :-)
    :
    : [code]
    : struct customer{
    : char name[21];
    : long tipsdone;
    : long sawsdone;
    : float time;
    : struct customer *next;
    : struct customer *previous;
    : struct customer *head;
    : struct customer *tail;
    : };
    :
    : void add_customer( void ){
    : struct customer *next;
    : FILE *customer_file;
    : char *new_customer = NULL;
    : char myname[21] = "";
    : struct customer current_customer;
    : size_t length;
    : size_t n = 20;
    : size_t io_size;
    : int duplicate = 0;
    : int i = 0;
    :
    : io_size = sizeof( customer );
    : if( customer_file = fopen( "customer.wmt","rb" ) ){
    : printf("
    file is opened
    ");
    : while( strcmp( myname , "EXIT") != 0 ){
    : printf("
    Please input the customer name :");
    : scanf( "%s" , myname );
    : if( length = strlen( myname ) <= 20 ){
    : if( strcmp( myname , "EXIT" ) != 0 ){
    : strncpy( current_customer.name , myname, n );
    : next = (struct customer *) malloc( io_size );
    : rewind( customer_file );
    :
    : while( fread( next, io_size, 1, customer_file ) == 1 ){
    : if( strcmp( next->name , current_customer.name ) == 0 )
    : duplicate = 1;
    : }
    : free( next );
    : if( duplicate != 1 ){
    : fclose( customer_file );
    : customer_file = fopen( "customer.wmt","ab" );
    : current_customer.tipsdone = 0;
    : current_customer.sawsdone = 0;
    : current_customer.time = 0;
    : fwrite( &current_customer, io_size, 1, customer_file );
    : fclose( customer_file);
    : customer_file = fopen( "customer.wmt","rb" );
    : }
    : else{
    : printf("
    Duplicate name.");
    : printf("
    Name not added to file.
    ");
    : duplicate = 0;
    : rewind( customer_file );
    : }
    : }
    :
    :
    : }
    : else{
    : printf("
    Must be less than 20 characters.");
    : }
    : }
    : }
    : else{
    : printf("
    Could not open file.");
    : }
    :
    : fclose( customer_file );
    : }
    :
    :
    :
    : struct customer *get_customers( void ){
    :
    : FILE *customer_file;
    : size_t io_size;
    :
    : struct customer current_customer;
    : struct customer *customer_pointer;
    : struct customer *temp_customer_pointer;
    : struct customer *customer_start = NULL;
    :
    : io_size = sizeof( customer );
    :
    : if( customer_file = fopen( "customer.wmt","rb" ) ){
    : customer_pointer = (struct customer *) malloc( io_size );
    : temp_customer_pointer = customer_pointer;
    : while( fread( customer_pointer, io_size, 1, customer_file ) != 0 ){
    :
    : if( customer_start == NULL ){
    : customer_start = customer_pointer;
    : customer_pointer->head = customer_pointer;
    : customer_pointer->previous = NULL;
    : customer_pointer->tail = customer_pointer;
    : customer_pointer->next = NULL;
    : }
    : else{
    : temp_customer_pointer->next = customer_pointer;
    : temp_customer_pointer->tail = customer_pointer;
    : customer_pointer->head = customer_start;
    : customer_pointer->previous = temp_customer_pointer;
    : customer_pointer->tail = customer_pointer;
    : customer_pointer->next = NULL;
    : }
    :
    : temp_customer_pointer = customer_pointer;
    : customer_pointer = (struct customer *) malloc( io_size );
    :
    : }
    : fclose( customer_file );
    : }
    : else{
    : if( customer_file = fopen( "customer.wmt","wb") ){
    :
    : puts("Customer file not found.");
    : puts("Please input customer name ");
    :
    : fflush(stdin);
    :
    : gets(current_customer.name);
    :
    : current_customer.tipsdone = 0;
    : current_customer.sawsdone = 0;
    : current_customer.time = 0;
    :
    : fwrite( &current_customer, io_size, 1, customer_file );
    : fclose( customer_file );
    : printf("
    Customer file was created");
    : return NULL;
    :
    : }
    : else{
    : printf("
    Could not create file.");
    : return NULL;
    : }
    : }
    : return customer_start;
    : }
    :
    :
    : [/code]
    :
    thanks once again but need two files linked need code
  • [b][red]This message was edited by dennisparker at 2005-4-1 9:5:49[/red][/b][hr]
    [b][red]This message was edited by dennisparker at 2005-4-1 8:45:28[/red][/b][hr]
    : :
    : thanks once again but need two files linked need code
    :


    I would love to provide the complete source code but unfortunately my boss has got me on a new project to write a program to determine if a glass is half full, or half empty. I hate these April 1 assignments!





Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories