Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

LINK TO THIS FORUM!

Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Partner With Us!

"Best Of Breed" Forums Add Stickiness To Your Site
Partner Button
(Download This Button Today!)

Feedback

"...I just wanted to say that you guys RULE, a million thank you's to whoever created, and/or manages this site. KEEP UP THE GOOD WORK..."

Geography

Where in the world do Tek-Tips members come from?

Replace string in file

ej2k (Programmer)
3 Jan 01 6:02
I have two questions:
Firstly, is it possible to replace a string in a file.

Secondly, (and linked to the first question), is it possible to manipulate some sort of cursor, in order to find this string within the file.  I currently have the words in the file held in an array of pointers.

Thanks in advance,
EJ
Nosferatu (Programmer)
3 Jan 01 11:50
Of course it is possible... The standard way to do it is to open 2 files, from one you read... and write in the other one... applying certain conditions on the output (ie. replacing your string).

As for your 2nd question... what do you mean by "manipulate some sort of cursor"? there is the file pointer as cursor which is used by the different ops, in the same general way - it shows how far you're in a file (from the beginning).

To locate more easily your string, you should use some index file along with the file where the string is located.

I gave you just some general ideas, hope this helps.
vkavith (Programmer)
3 Jan 01 22:12
You could also think of over writing the current file too, or to make things simpler (but lenghtier) read all the contents of the first file into a data structure and then go about replacing the string. Finally write the new contents of the data-structure back to the same or a new file.

Its yr choice now... :)

Sriks

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Back To Forum

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close