Having a hard time shifting elements
Hello,
I am trying my best to shift to the next elment in my array. But its not working. The first element shifts just fine, but after that, the value from the first moves to the next.The objective of the program is to prompt the user for a string(which UserString02) is, then take that input and compare it to the alphabet of characters and move it n spaces from the character. For example, if someone enters in ABC and also enters in 3, A will be moved to D, B will be moved to E and C will be moved to F. Here is the code I have
Code:
for(int i=n-1; i>0;i--) //n is the length of the string
{
for(int j=0;j<LIMIT;j++) //Limit is the number of characters in the alphabet.
{
if(UserString2[i]==Alphabet[j])
{
UserString2[i] =Alphabet[k];//k is the amount of spaces the user wants the character to be moved to to be switched to another character.
UserString2[i]=UserString[i-1];
}
}
}
any help will be greatly appreciated. thanks