string modification
Oct 8, 2014 at 4:47am UTC
hi everyone! i have to write a function to modify the input string by substituting each alphabetical character. for example, 'Programming' to
'Rtqitcookpi' (mod_int = 2). Thanks.
Oct 8, 2014 at 5:00am UTC
I was at first confused by your using 'mod' -- which is a mathematical term for modulus (or, here, remainder).
The strictly technical way of expressing it is:
For each character value x in your string S :
x = x + 1
Hopefully, expressing it this way helps. Start by making a function that takes a string:
1 2 3 4
void encode( char * s ) // void encode( string& s )
{
... // does something here to s
}
Inside the function, loop through each character in the string and modify it.
Then you can use your function easily enough:
1 2 3 4 5 6
int main()
{
char str[] = "Programming" ; // string str = "Programming";
encode( str );
cout << str << endl;
}
If your assignment is to use the
std::string type, just change things as the comments indicate.
Hope this helps.
Topic archived. No new replies allowed.