C++ code to read an as400 work file and form the data structure.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • associate
    New Member
    • Apr 2010
    • 1

    C++ code to read an as400 work file and form the data structure.

    My question is similar to the Kevin asked about reading a flat file from COBOL using C.
    I have to do the same using C++ and I am new to C++.

    I need to read the file one record at a time.
    My file record is as below:

    Field Name Type Length

    Emp Name alphanumeric(A) 10
    Emp Age alphanumeric(A) 3
    Emp Salary Zoned Dec(S) 10

    If there are 10 records in my file, I want to process one record at a time and want to store the information using C++ in some structure say Emp_Struct?

    Can somebody help me with the sample C++ code?

    Regards,
    JK
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    Break your program into functional sections then use the sections to write tyuor program.

    For example, write a function to read one record from your file and put the data into an array you pass in as an argument. Use the return value to signal the read was OK ot that you reached end of file. This will get all your read logic in one spot.

    Then write a struct with your desired data members.

    Then write a function that processes your array. You pass in the array plus the address of one of your struct variables. This function goes through the array and loads the struct data members.



    Your main() starts to look like:

    open the file
    create array of struct variables
    Pass element of struct array to read function
    Repeat the above until read function returns end of file.

    etc...

    Comment

    Working...