I need to replace some chars with multiple chars (a string), but I got stuck. This code works for replacing one char with another, but if the replacement are multiple chars, the output messes up.
Here is the code I have so far:
char input[50];
char output[150];
int i;
printf("Enter your text: ");
fgets(input, 50 , stdin);
for (i = 0; input[i] != '\0'; i++){
switch (input[i]){
case 'a': output[i]= '4'; break;
case 'd': output[i]= '|)';break;
case 'e': output[i]= '3'; break;
case 'f': output[i]= '|='; break;
case 'u': output[i]= '|_|'; break;
case 'w': output[i]= '\|/'; break;
/* REST OF THE ALPHABET
INTENTIONALLY SUPPRESSED*/
}
}
printf("Your new text is: %s", output);
return 0;
As suggested by dasblinkenlight, I set another index for the output, That worked pretty fine, but I getting two additional chars at the end of the output text... where does those chars come from?
This is an example:
Enter your text: afedef Your new text is: 4|=3|)3|=■(