Click here to Skip to main content
15,881,877 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have 2 files,
first
t1- x,y,z
t2- a,b,c
.
.
so on

second
x=1
y=2
z=3
a=4
.
. so on

I want to replace the content of file one wrt file second
example
t1- 1,2,3
t2- 4,5,6
.
.
so on.
Posted
Updated 28-Mar-12 5:59am
v2
Comments
Chandrasekharan P 26-Mar-12 13:43pm    
Anil, where are you stuck?? or is it that you are expecting us to give you the code??

We do not do your homework: it is set for a reason. It is there so that you think about what you have been told, and try to understand it. It is also there so that your tutor can identify areas where you are weak, and focus more attention on remedial action.

Try it yourself, you may find it is not as difficult as you think!
 
Share this answer
 
Comments
theanil 26-Mar-12 14:06pm    
Hey its not my homework
You have to parse both the files.
If your files are really so regular then you may just use profitably fscanf and fprintf for the job.
For instance
C
if ( fscanf(fp "%c=%d", &name, &value) == 2)
{
  // here add the pair {name, value} to the look up table
}

is a very rough line-parser for second file entries.

If you need to handle more complex scenarios (for instance multiple blanks, longer identifier names) then you may use awk or parsing tools tools like bison & flex.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900