0

I keep getting an extra characters added to the end of my char arrays. When I execute the code below, I get "Hash: 50jMstBtCmj7s roflC}B. Where did the extra C}B at the end of the key array come from? I can't seem to get rid of it, and it's throwing off the results of the crypt() call. Thanks in advance.

string salt = "50";
char key[4] = "";
string s;

//key = '';
key[0] = 'r';
key[1] = 'o';
key[2] = 'f';
key[3] = 'l';
s = crypt(key, salt);
printf ("Hash: %s %s\n", s, key);
return 0;
1

Since you assigned each char in the string one at a time, did you remember to add the end of string marker? If not, printf will print whatever garbage data that follows until it finds random data that looks like the EOS marker \0.

BTW, did you remember to leave room in the declaration of key[] for the EOS marker?

If this answers your question, please click on the check mark to accept. Let's keep up on forum maintenance. ;-)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .