Could somebody please tell me how to use a loop to encrypt a string by adding 1 to the ASCII value of each character in the string? EX "apple" to "bqqmf"? Thank You very much
Could somebody please tell me how to use a loop to encrypt a string by adding 1 to the ASCII value of each character in the string? EX "apple" to "bqqmf"? Thank You very much
for(int x = 0; x < strlen(mystring); x++)
{
mystring[x]++;
}
Code:for(int x = 0; x < strlen(mystring); mystring[x++]++);
Quidquid latine dictum sit, altum sonatur.
Whatever is said in Latin sounds profound.
what if it's on 'z' does it go to 'a'?
- 0927
- a.k.a 0 9 two 7
nope, in that case you might want something like this:
Code:char EncryptChar(char ch) { if (ch == 'Z') return 'A'; // that is if you care about uppercase if (ch == 'z') return 'a'; return ch + 1; } void EncryptString(char *str) { while (*str != '\0') *str = EncryptChar(*str++); }