Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need help with search and subsitute.

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
Hi all,
I programming in win32 application environment.I want to make a program that ask for a name.Then have it read a data file.(one big paragraph) Everytime it finds the percentage charactor I want it to replace it with the First name that it ask for in the beginning.
Example of how it should works.
First I input the name John or what ever into a variable.
Next this is what it reads in from the data file.txt
-> Dear %,
You have won a million dollar.
% have a good day.

And this is what it to do.
->Dear John,
John have a good day.

So you see everytime it finds a percentage charactor(%)
I would like it to subsitute it with the name john or what ever the user inputs.And when its done I like it to
cout the paragraph after the percentage charactor has been
subsituted.

So how can I create something like that? PLease help.Thanks in advance.
 
Maybe workaround it make more sence:

#include<iostream>
#include<fstream>
using namespace std;
int main()
{
char name[100];
cin>>name;
ofstream xxx(&quot;xx.txt&quot;);
xxx
<<&quot;Dear &quot;<<name
<<&quot;, You have won a million dollar.&quot;<<name
<<&quot; have a good day.&quot;<<endl;
return 0;
} Ion Filipski
1c.bmp


filipski@excite.com
 
that was great but not what I had in mind.
ok first it gets input from the user.
Then it reads from a data.txt file that contains the content->
Dear %,
You have won a million dollar.
% have a good day.
into a charactor array or string.
Then I would like it to subsitute the percentage charactor with the input from the user. And c-out onto screen
->Dear John,
John have a good day.


All I want to create is a program that personalize a form letter by subsituting the percentage charactor in the data file.txt with the user input name.

ANyone know how to do it?

 
You could put it all in a cstring and use Replace

OR to read in the file use infile.getline(buffer,length,'%');


this will stop it at a percent and follow that up with a

infile.get()
infile.getline(as above) // loop


Matt
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top