i tried to make something like a secret code using ASCII number as a base of it.
so the code will convert the inputed string from user into the ASCII first, after that it will change the number obtained with base an array that already assigned in code.
so far my code doesn’t want to run and sometime it will only print out the number or nothing at all, can someone explain to me where do my logic got wrong?
#include <stdio.h>
#include <string.h>
char symbol_mapping[][10] = { // 12 rows (strings)
"91", "$", "#(", ">_!", "*", "<-", "LK", "g7", "Hel", "kk", "+="
};
char* convert_function(char input_char) {
int ascii_code = (int)input_char;
if (ascii_code < 0 || ascii_code > 127) {
return "?";
}
return symbol_mapping[ascii_code]; // Return the corresponding string (for special codes)
}
int main(void) {
char input[50];
int ascii_codes[50]; // Array to store integer ASCII codes
printf("Enter a string (up to 49 characters): ");
fgets(input, sizeof(input), stdin);
int length = strcspn(input, "n");
if (input[length - 1] == 'n') {
input[length - 1] = '';
}
printf("ASCII codes of the characters: ");
for (int i = 0; i < length; i++) {
ascii_codes[i] = (int)input[i];
printf("%s", convert_function(ascii_codes[i]));
}
printf("n");
return 0;
}
here is the output that i want for example
Enter a string (up to 49 characters): 1Ap
ASCII codes of the characters: *<-+=g7LK$$#(
but i get this kind of output :
Enter a string (up to 49 characters): 1Ap
ASCII codes of the characters: 4965112
1