For example when I input in the terminal
hello there
it prints
gmllg mgmkm
instead of printing
itssg zitkt
which is not supposed to happen.
Another example is when I input in the terminal
abcdefghijklmnopqrstuvwxyz
it prints
jvmkmnbgghaldfghjklmbcvbnm
the last 5 characters are right but its supposed to print
qwertyuiopasdfghjklzxcvbnm
Anyways I can fix this?
Here is the code below
#include <cs50.h>
#include <stdio.h>
#include <string.h>
void replace_char(string text, string replace, string new);
int main(void){
string message = get_string("Type message: ");
string Alpha = "abcdefghijklmnopqrstuvwxyz";
string Key = "qwertyuiopasdfghjklzxcvbnm";
replace_char(message, Alpha, Key);
printf("%s\n", message);
}
void replace_char(string text, string replace, string new){
int strl = strlen(text);
int h;
int p;
for (h = 0; h < strl; h++){
for (p = 0; p < 26; p++)
if (text[h] == replace[p])
text[h] = new[p];}
}