Hi everyone,i have this program for an school assignment. the goal of program is that encodes the user name part of a given e-mail address and creates a password.
Degug Assertion Failed
Expression:String Subscript out of range
I couldn't find the wrong part.How can I fix this problem?
It is not necessary that an object of type std::string has the terminating zero-byte. You should use member function size() as the upper limit of the loop. For example
1 2 3 4 5 6 7 8
void tolower( string &input )
{
for ( std::string::size_type i = 0; i < input.size(); i++)
{
if ( input[i] >= 'A' && input[i] <= 'Z' )
input[i] = input[i] - 'A' + 'a';
}
}
Hi everyone again. I want to help from you for my code writing. I want to write second encoding part on my program according to the task but I couldn't find proper way. Can anyone help me to write second encoding part?
I wrote first part, you can see my code above
Encoding Steps:
1. Replace any vowels (i.e., "a", "e", "i", "o", "u") in the user name with their ASCII values.
For example, if the user name is "canangunicen", then you have to replace "a" with "97", "u" with "117", "i" with "105", and lastly "e" with "101". Thus, the encoded version becomes "c97n97ng117n105c101n". After this process is done, you have one more step to finish the encoding.
2. When the first part of the encoding is finished, in the encoded string, you will have only digits and consonants (e.g., "c97n97ng117n105c101n"). Now, you have to encode the consonants as follows:
a. For each consonant in the encoded user name, if you can find the same character in the provider name, then you will replace it with the one that is on the left side of the found character in the provider name. For example:
user name = canangunicen provider name = sabanciuniv
After the vowels are replaced with their corresponding ASCII values, the encoded string will be the following:
c97n97ng117n105c101n
Then, you will replace the consonants according to their positions in the provider name. For instance, if you are processing 'c' currently, you would find the position of 'c' as 5 in the provider name. Thus, in the encoded string, you will replace 'c' with 'n', since 'n' is the character which is on the left side of 'c' in the provider name. At this point, the encoded string will become "n97n97ng117n105c101n".
If you find the character you are searching for at the 0th index in the provider name, then in the encoded string, you have to replace it with the last character of the provider name.
If the character you are searching for exists in multiple positions in the provider name, then you have to consider the one with the smallest index.
b. For any consonant in the user name, if you cannot find the same character in the provider name, then you will replace it with the first character of the provider name.
For example, since there is no 'g' in the provider name, the encoded string will become "n97a97as117n105c101n" after processing 'g' in the encoded user name.