0

I am trying to make this output a character encrypted with a key(which is an int) it just outputs some numbers or something.

printf("%c", (((p[i] - 65) + (k[j] - 65)) % 26) + 65;);
0

Why do you have extra ; ? .I guess it is here syntactic error. Without that it should work. It does not even compile if you have this.

For example:

p[i] = 65;
k[j] = 66;

Following line should print B

printf("%c", (((p[i] - 65) + (k[j] - 65)) % 26) + 65); 
| improve this answer | |
  • No, that's not it, it's just printing some random numbers – Lando Jongeward Jun 15 '16 at 17:48
  • then please explain your question. can you give examples of p[i] and k[j] ? what do you expect as a output? edit your question. it is not clear – Wafeeq Jun 15 '16 at 17:53
  • For me, it worked and it printed a character. – Wafeeq Jun 15 '16 at 17:54
0

Okay, so my problem was that I had already set the key to it's shift value and I didn't have to subtract 65 from it, this worked for me:

printf("%c", (((p[i] - 'a') + k[j]) % 26) + 'a');

outputs b if p[i] = a and j[j] = 1.

| improve this answer | |

You must log in to answer this question.

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