>Also, you are passing a char array to a char pointer so that just won't work.
Why not? The name of an array is simply a pointer to the first element of that array, so passing a char array by name to a char pointer is perfectly legal
As for the actual program, here's a compactisized version
Code:
#include <stdio.h>
void leet(char *y);
void ask(void);
int main(){
ask();
return 0;
}
void ask(){
char phrase[100], *y, ans[5];
puts("Would you like to translate something? (Y or N)");
fgets(ans, sizeof(ans), stdin);
if(strcmp(ans, "Y") == NULL || strcmp(ans, "y") == NULL){
puts("What do you want to translate?");
leet(fgets(phrase, sizeof(phrase), stdin));
}else if(strcmp(ans, "N") == NULL || strcmp(ans, "n") == NULL){
puts("You are the weakest link, goodbye!");
getchar();
exit(0);
}else{
puts("That is not an option, you moron.");
puts("Press any key to return to the REAL WORLD...");
getchar();
ask();
}
}
void leet(char *y){
while(*y != '\0'){
switch(*y)
{
case 'e':
case 'E':
putchar('3'); y++;
break;
case 'o':
case 'O':
putchar('0'); y++;
break;
case 'T':
putchar('7'); y++;
break;
case 'A':
case 'a':
putchar('4'); y++;
break;
case 's':
case 'S':
putchar('$'); y++;
break;
default:
putchar(*y); y++;
break;
}
}
putchar('\n');
ask();
}
I tried to keep it as similar to what you had as possible while still within the bounds of reason. I got rid of your x variable since it wasn't doing anything useful, fixed your switch to remove redundancies, killed the first switch because it was just taking up space and replaced it with an if-else, and just scrunched everything up and made it a bit tidier. I could make it smaller, but then it wouldn't look anything like your program, so I didn't do that.
-Prelude