Hi All,
Can someone please help me with the code in C / C++ to find a string in an input text file and replace it with another string in output text file. The catch is that white spaces in the input file should be retained in output file. And, if possible we should be able to replace multiple search strings with multiple replace strings. e.g;
srch1, srch2, srch3 in in.txt should be replaced by rplc1, rplc2, rplc3 in out.txt
Thanks.
5 8302
Have you tried using getline() and strtok()?
Hi,
I forgot to mention that I need the code for Windows platform. So I can not use sed, getline() as they are not available in Windows.
Thanks.
Hi,
I forgot to mention that I need the code for Windows platform. So I can not use sed, getline() as they are not available in Windows.
Thanks.
I'm pretty sure getline is available in Windows, what headers are you including in your program?
Solved:
while (fgets(str, 80, infile) != NULL) {
while ((srchstr = strstr (str, "my")) != NULL)
memcpy(srchstr, "yo", strlen("yo"));
while ((srchstr = strstr(str, "this")) != NULL)
memcpy(srchstr, "that", strlen("that"));
fputs(str, outfile);
}
Solved: -
while (fgets(str, 80, infile) != NULL) {
-
while ((srchstr = strstr (str, "my")) != NULL)
-
memcpy(srchstr, "yo", strlen("yo"));
-
while ((srchstr = strstr(str, "this")) != NULL)
-
memcpy(srchstr, "that", strlen("that"));
-
fputs(str, outfile);
-
}
-
Please follow the guideline while you do post.
Kind regards,
Dmjpro.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: hokieghal99 |
last post by:
import os, string
print " "
setpath = raw_input("Enter the path: ")
def find_replace(setpath):
for root, dirs, files in os.walk(setpath):
fname = files
for fname in files:
find =...
|
by: Xah Lee |
last post by:
suppose you want to do find & replace of string of all files in a
directory.
here's the code:
©# -*- coding: utf-8 -*-
©# Python
©
©import os,sys
©
©mydir= '/Users/t/web'
|
by: rbt |
last post by:
Here's the scenario:
You have many hundred gigabytes of data... possible even a terabyte or
two. Within this data, you have private, sensitive information (US
social security numbers) about your...
|
by: Vic |
last post by:
Hi,
With VBA code from MSAccess, how to search for a string in another
text file, and replace it with space and then save it under the same
name? Your help is greatly appreciated.
Rgds
|
by: Neo Geshel |
last post by:
This works:
<form>
<asp:TextBox id="name" />
<%= name.ClientID %>
</form>
But this DOES NOT work:
<form>
|
by: Xah Lee |
last post by:
Interactive Find and Replace String Patterns on Multiple Files
Xah Lee, 2006-06
Suppose you need to do find and replace of a string pattern, for all
files in a directory. However, you do not...
|
by: Dmitridj |
last post by:
Heya everyone,
I'm trying to write a program that finds and replace an array of
characters defined by the user in a text file. Basicly the program
finds and replaces a substring typed in by the...
|
by: TOXiC |
last post by:
Hi everyone,
First I say that I serched and tryed everything but I cannot figure
out how I can do it.
I want to open a a file (not necessary a txt) and find and replace a
string.
I can do it...
|
by: mouac01 |
last post by:
Newbie here. How do I do a find and replace in a binary file? I need
to read in a binary file then replace a string "ABC" with another
string "XYZ" then write to a new file. Find string is the...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
| |