I am trying to replace a particular character in a string with all the letters read from a file.

for example, i have a replace.txt which contains all the replacing characters like '#' and '&'.
If my string is "array",character 'a' has to be replaced. The program should generate combinations like "#rray","#rr&y","#rr#y","&rr&y","&rr#y","&rray","arr#y" and "arr&y".

can anyone provide a solution to this?
Also how to use char* instead of char[]?

pan64

03-25-2013 05:30 AM

i think it is your homework, so do you have any code written?

kooru

03-25-2013 10:38 AM

Quote:

Originally Posted by arungpillai09054
(Post 4918233)

Can anyone provide C code to generate these combinaions ?

Hi arungpillai09054 :)
Have you tried to write a code for this? Where you are stopped?

TB0ne

03-25-2013 10:54 AM

Quote:

Originally Posted by arungpillai09054
(Post 4918233)

I am trying to replace a particular character in a string with all the letters read from a file.

for example, i have a replace.txt which contains all the replacing characters like '#' and '&'.
If my string is "array",character 'a' has to be replaced. The program should generate combinations like "#rray","#rr&y","#rr#y","&rr&y","&rr#y","&rray","arr#y" and "arr&y".

Can anyone provide C code to generate these combinaions ?

No..we're not going to do your homework for you, but we will be more than happy to HELP you if you're stuck. So, post what you've written/tried, what results you're getting, etc., and we can assist. Otherwise, do your own homework.

psionl0

03-25-2013 11:33 AM

It sounds like recursion might help you best. When your pointer reaches the first replaceable character in the string, substitute in turn each character from replace.txt (including the character to be replaced) then do a recursive call for the remainder of the string. You would still have to eliminate the string that ended up with no characters replaced.