The code is supposed to translate certain characters into other characters.
My issue is this, when inputting characters to translate, it does it fine but only up to the 8th character.
Example:
AAAAAAAAA is supposed to be @@@@@@@@@,
but what it translates to is
@@@@@@@@A.
Can anyone help?
#include void secrefy(char* secret) { int b = sizeof(secret); for(int a = 0; a < b; a++) { switch(secret[a]) { case 'a': secret[a] = '@'; break; case 'A': secret[a] = '@'; break; case 'e': secret[a] = '3'; break; case 'E': secret[a] = '3'; break; case 'h': secret[a] = '#'; break; case 'H': secret[a] = '#'; break; case 'p': secret[a] = 'q'; break; case 'P': secret[a] = 'q'; break; case 's': secret[a] = '$'; break; case 'S': secret[a] = '$'; break; case 't': secret[a] = '+'; break; case 'T': secret[a] = '+'; break; case 'x': secret[a] = '*'; break; case 'X': secret[a] = '*'; break; } } } int main(void) { char secret[]="AAAAAAAAA"; secrefy(secret); printf("Encrypted will be %s", secret); }
sizeof(secret);is only size of pointer , which is not equal to your passed string inside your functionsecrefy(), better pass size while calling function or usestrleninsidesecrefy()