ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
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.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I'm trying to find a way to search and replace words in a file. I figured i'd try fseek() to help me but I'm still unsure of how to do it. Could I get your input/links.
GNU Search and Replace gsar has already done it -
search and replace is a somewhat complex thing.
You can download the source here to see how it works -
Hmm, what if I was to make the program look at the text and then output the changed text to a file?
Ok, to understand better, I'm trying to create a intel asm to at&t asm syntax changer. The program will basicly grab intel asm source code and change all of it's code into at&t syntax. So, I need to change all the registers from reg to %reg and change instructions as well.
So basicly, I'm trying to find a way to do this with less effort possible. So my program should :
1.Take first line
2.Examin first line
3.Change what needs changing
4.Go to line++
5. End of line? yes quit, no continue to 6.
6.Go to 1
I wrote some code, not sure if it works, what's your opinion?
Code:
int inChar,location=0;
while ((inChar=getc(infile)) != EOF) {
if ((inChar=getc(infile)) != " ") { // If not a space
takethis[location] = inChar; // put the character in takethis
takethis[location+1]='\0'} // add 1 and add a end of line
location++; // keep going through the list untill we get
// a space
for (i, i<12, i++) {
if ( strcmp(takethis, lookup[i]) == 0 ) { // at space, take what we had
sprintf(fileout, replace[i]+" "); // look it up in lookup list
} // end if // see if it needs replacing and
} // end for // do it
location++; // needed so I can keep going after the space
} // end while
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.