The problem you have is:
printf("The key is:\n\t %s", key);
You are passing an array of pointers to printf, and what you would like to do is
printf("The key is:\n\t %s", key[0]);
Another problem is that you have indicated as many pointers as you have characters in your password, so you overwrite the array of pointers that you reserved, because key takes place only for two pointers, not for N, which is the main reason for your "bad pointer".
And one more thing that is not related to this error is that you should not throw malloc , nor do you need to multiply it with sizeof(char) , since by definition it will always be 1.
source share