Link to home
Start Free TrialLog in
Avatar of anilkumarv
anilkumarv

asked on

Reading a File

I have files in the following format:

Basket 1:
    Field1=xxxx
    Field2=xxx
    Field3=xxx
Basket 2:
    Field1=xxxx
    Field2=xxx
    Field3=xxx
Basket 3:
    Field1=xxxx
    Field2=xxx
    Field3=xxx
Basket 4:
    Field1=xxxx
    Field2=xxx
    Field3=xxx
...........and so on

No of baskets varies in each file.But the no. of fields are same in each basket.

My aim is:
Based on the Field1 value in each basket I want perform some
operations on Field2 and Field3 values and write the output to some other file.

Can somebody help, how to start.any sample code will be more helpful.
Avatar of Answers2000
Answers2000

The basic approach is

(a) Read the file into a buffer using fopen, fread, fclose
(b) parse the buffer into an internal data structure (say an array in C, or map/multimap in C++ - easier with C++).  Use strchr or similar to break on new lines, colons, equals or other significant characters.
(c) Modify internal data structure
(d) Write out internal data structure using fopen, fwrite, fclose

Which part of the above do you need help on - or all of em ?
Avatar of anilkumarv

ASKER

Mainly i need help in parsing.

thanx
use strtok to split up input lines
I would put it in an ini file and use the windows ini file reading functions to read it. They are very easy to use.


I am on unix not on windows.


ASKER CERTIFIED SOLUTION
Avatar of alexo
alexo
Flag of Antarctica image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial