I am trying to shift keyboard's key 2 digits to the right, for example if user wants to type "a" they have to press the "d" key on the keyboard, "p" to "]".
Which mean if the user input is: "p m[ojku d, d]]'t/",
then the output will be: "i bought an apple,".
Excluding the uppercase key and last the keys in its row on the keyboard.
The way I am doing it is to check every char of the string and compare its ASCII to each case, it works perfectly fine. But I feel so dumb by doing so, wanna know is there any algorithm or smarter way to accomplish this.
while (fgets(inputString, 500, stdin)) {
stringLength = strlen(inputString);
for (int i = 0; i < stringLength; i++) {
switch (inputString[i]) {
case 100:
outputString[i] = 'a';
break;
case 109:
outputString[i] = 'b';
break;
case 98:
outputString[i] = 'c';
case 47:
outputString[i] = ',';
break;
case 50:
outputString[i] = '`';
break;
case 92:
outputString[i] = '[';
break;
default:
outputString[i] = inputString[i];
}
}
printf("%s", outputString);
}
lookup['d']
containsa
. – Blastfurnace Nov 14 '19 at 12:11'@#£
also varies. – Weather Vane Nov 14 '19 at 12:18