ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
In a Linux C program I'm working on, there's a part where I need to substitute a string within a file with another string; the data in the file after the new string should either be moved back or moved forward, depending on whether the new string is longer or shorter than the previous one.
An example of what I'm referring to is if you have a particular web page pulled up and you save that page to disk; each of the files within that page are saved in a subdirectory, and inside the HTML file, the new pathname for each of those files replaces the original pathname, i.e., "http://www.aol.com/script.com" becomes "aol_files/script.com".
There doesn't seem to be a real efficient way to do something like this. I was thinking that since these substitutions are within a file, I could use 'mmap' and bring the file contents into memory, make the desired changes and 'munmap' it. But that wouldn't make the string modifications any more straight-forward. I thought I'd ask to see if anyone had any suggestions of ways to go about this that I hadn't thought of (other than the cumbersome method of moving the data, char-by-char, to where it's supposed to be. Thank you in advance.
It is not possible to gain an understanding of your entire pattern space with just one example. If you are asking for algorithms or help designing such, we need to better clarify your pattern -> replacement transitions. Please show several example transitions.
You are correct that the input method of the file contents into your program is a different matter.