Click here to Skip to main content
12,349,582 members (29,107 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C Linux
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 26-Mar-12 7:25am
theanil4.7K
Edited 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??
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

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!
  Permalink  
Comments
theanil 26-Mar-12 14:06pm
   
Hey its not my homework
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

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
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.
  Permalink  
v2

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160621.1 | Last Updated 28 Mar 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100