-2

Possible Duplicate:
Replacing a word in a file, using C

i am doing filing in c language. i have created a txt file and write some data into it. but as my program progress i have to search some text and replace it with the other word but the problem i am facing is that suppose in my file i wrote

"i bought apple from the market"

if i replace apple with pineapples , as apple has 5 char and pineapple has 9 char it will write it as

"i bought pineapple m the market"

that it also has affect the words written after apple because of the different char length

i have use fseekpos function to find the pointer position

thanks

Community
  • 1
  • 1
mainajaved
  • 7,905
  • 10
  • 36
  • 44
  • 1
    Everything's correct. What's the question then? –  Feb 18 '11 at 14:38
  • 2
    sounds like an assignment from school. you should try to figure things out yourself in order to learn. if not, use something better to change things with like sed. – murrekatt Feb 18 '11 at 14:38
  • 3
    Same question by same user (different account) here: http://stackoverflow.com/questions/5042196/replacing-a-word-in-a-file-using-c – Shawn Chin Feb 18 '11 at 14:39
  • I THING U PEOPLE NOT GETTING ME. I AM ASKING HOW TO APPEND WORDS IN BETWEEN SOME WHERE IN THE FILE.. THANKS – mainajaved Feb 18 '11 at 14:47
  • for eg i the file i have " i go to market" how to make it "i go super market" want to insert super in between thanks – mainajaved Feb 18 '11 at 14:49

1 Answers1

0
  • take all data with io function
  • store it in double pointer ( use two dimension )
  • after seeing EOF, clear the used file, close it
  • write some function to do your task and manipulate the data stored in two dimension
  • open it again, but now to write the manipulated data in it