Thread: Program won't save a record

  1. #1
    Registered User
    Join Date
    Oct 2001
    Posts
    5

    Angry Program won't save a record

    Can anybody see what I'm doing wrong with the attached program. It's a file update program that read a record from a newly sorted customer file, then reads the update required and then executes the update.
    All this works fine until it tries, without sucsess, to save the record to a new updated customer file. If tried everything and nothing seems to work.
    I would be eternally grateful if someone could give me a point in the right direction.
    Cheers

    P.S Don't run the program as it's not quite finished yet, suggest stepping through until fread() funtion is encountered
    Last edited by Delboy; 11-21-2001 at 11:31 AM.

  2. #2
    Registered User
    Join Date
    Aug 2001
    Posts
    22
    Hi,
    I find it very difficult to go through your code.
    Give comments and brief the exact problem.
    Also tell the Objective of the program.
    If possible try to give some sample run so that
    everybody can give you an appropriate solution.
    Try to tell where exactly the problem is according to your idea.


    Thanks
    By
    A.Sebasti..

  3. #3
    Registered User
    Join Date
    Oct 2001
    Posts
    5

    Thumbs up Reply

    Sorry about that. New user:
    The programs purpose is to update a customer file with either a reciept or issue of stock, deletion of stock or the creation of a new customer.
    The program starts by opening files needed for the program. This works fine (I think).
    The files are:
    502063SF.DAT - This is a previously sorted and validate file of customer records which will be used for updating.
    ZENCF.DAT - This is the customer file to be updated.
    NEWCUSTMAST.DAT - This is to be the newly updated customer file. (This is the one I am having problems saving records to).
    STCKMAST.DAT - A file of the products together with the amount of each product in stock and their prices
    LPT1 - Printer

    After printing some page headings which I haven't done yet it then allocates a block of memory the size of the structure MAST_REC. Then a record form ZENCF.DAT is read into this block (pointed to by m_ptr) and a record from 502063SF.DAT is read using the function read_record.

    As the records from 502063SF.DAT are 3 differnt types (issue/reciept, deletion. creation) the record is read as a string, the size of this string determined, the file pointer reset, and then it is read into it's appropriate structure (the 3 structures are in a union).

    The customer code of the record from ZENCF.DAT is then copied in the variable 'marker' and this is used in a strcmp() funtion to determine the next step in the program.

    If the result of the compare is less than 0, the create_customer() function is called and only if the record type of the record from 502063SF.DAT is 'C' will the operation continue. Otherwise an error message will be printed. (It's output is on screen at the moment for the purpose of testing).
    If the result of the compare is 0 then the update_customer() function is called. This will update the record from ZENCF.DAT. Firstly it determines the record type. If it is 'D' the delete_fuction() is called and the customer is deleted providing they have a zero balance, otherwise an error message is executed. If the record number is 'R' or 'I', then the issue_receipt() funtion is called. This searches for the stock from the file STCKMAST.IDX which is open in the ISAM header file. If the stock cannot be found, the appropriate messgage appears else the record is updated by adding/subtracting the value of the (stock*price).

    The next record from 502063SF.DAT is then read and this will continue until the customer code is greater than marker.
    When this occurs the record pointed to by m_ptr is saved to the file NEWCUSTMAST.DAT. This is were it goes tits up. I've tried all different ways of saving the file but nothing seems to work and this is my sticking point.

    The program isn't ready to run yet as I have to smooth out a few(!!!!) rough edges but on a walk through(F7 or F8 on my BORLAND compiler) it still doesn't save and it does on other file updates programs that I've written.

    Thanks again for taking a peek
    Last edited by Delboy; 11-21-2001 at 06:50 AM.

  4. #4
    Registered User
    Join Date
    Aug 2001
    Posts
    247
    welcome delboy, joining the rest of us computeach void main gang. lol
    hoping to be certified (programming in c)
    here's the news - I'm officially certified.

  5. #5
    Registered User
    Join Date
    Oct 2001
    Posts
    5

    Talking Void main

    Apartly is a trademark we're all cursed with

  6. #6
    Registered User
    Join Date
    Oct 2001
    Posts
    5

    Talking Update

    To anyone who's downloaded my problem. Thank for the interest but I forgot to include an important file. I've updated it now and the file is included. Please download again. Thanks again. D
    Last edited by Delboy; 11-21-2001 at 11:38 AM.

  7. #7
    Registered User speedster's Avatar
    Join Date
    Feb 2002
    Posts
    7

    Stock file??

    Hi computeach student.
    If this is question 3 of excercise 4 stage three.
    Why all the files when the question askes only for a stock file to be updated ??.
    If not then ignore nosey oll me lol.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C program using structs to calculate grades
    By TampaTrinDM88 in forum C Programming
    Replies: 4
    Last Post: 07-06-2009, 12:33 PM
  2. Replies: 20
    Last Post: 06-12-2005, 11:53 PM
  3. String sorthing, file opening and saving.
    By j0hnb in forum C Programming
    Replies: 9
    Last Post: 01-23-2003, 01:18 AM
  4. Help w/project + linked list Plz Read
    By havoq93 in forum C++ Programming
    Replies: 13
    Last Post: 10-27-2002, 02:53 PM
  5. help to modify record in txt (binary)
    By Unregistered in forum C Programming
    Replies: 4
    Last Post: 01-29-2002, 06:32 PM