I'm havin a problem with this coe bellow.
It's supposed to transform text on the wall to text user wants e.g. from "efgh afao gagsw" --> "###h ###o ####w".
My code keep on chrashing when it gets to function Vandal :/
I know it would be better to use chars and then pointers :D
#include <iostream>
#include <string>
usingnamespace std;
void Vandal(string T1, string T2)
{ int n=T1.size();
for (int i(1);i<=n;i++)
{
if(T1[i]!=T2[i])
T1[i]='#';
}
cout<<T1;
}
int main()
{ string napis, cilj;
int n;
cout<<"What's written on the wall...\n";
getline(cin, napis);
cout<<"What would you like to be on the wall...\n";
getline (cin,cilj);
Vandal(napis, cilj);
return 0;
}
variable i needs to be initialized with 0 and cycle goes till i<n ...
from what you have written, you want spaces to be left as spaces, so you need to check if character == space
Done that...It's not chrashing now ty.
It wasnt working at all so I didn't bother with spaces so far :D
But yeah they should be left as spaces.
But no I have a problem that his code only checks paralel characters, like first in T1 with first in T2, so there is hardly any chance to get the output you would want. So how should I do that It would keep checking for one particulat charaster and went throught whole loop.
Also if you are trying to modify the strings so that changes remain after control gets back to main, you should be passing the string variables by reference rather than by value