Click here to Skip to main content
12,890,879 members (55,045 online)
Rate this:
Please Sign up or sign in to vote.
See more: C Linux
I have 2 files,
t1- x,y,z
t2- a,b,c
so on

. so on

I want to replace the content of file one wrt file second
t1- 1,2,3
t2- 4,5,6
so on.
Posted 26-Mar-12 7:25am
Updated 28-Mar-12 5:59am
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
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!
theanil 26-Mar-12 14:06pm
Hey its not my homework
Rate this: bad
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.

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
Web01 | 2.8.170424.1 | Last Updated 28 Mar 2012
Copyright © CodeProject, 1999-2017
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