[code hidden per academic honesty guidelines]
You have a few issues going on here.
If the plain text string is longer than the key, it will go past the end of the key string with unpredictable results. You tried to address this with:
int p = 0; int k = p % keylen;
but all this does is set k to 0. Doing the
% keylen here doesn't do anything later. It needs to be done each time k is incremented. Also, later, there's no need for p. You can simply do something like
k = k % keylen.
Your key will be out of synch with the plaintext because you are incrementing k before the encoding instead of after, so you're using the wrong key char - the next one.
This code assumes that the key and the plaintext are both the same case. What about when one is uppercase and the other is lowercase?
That should get you started. There may be other issues.
If this answers your question, please click on the check mark to accept. Let's keep up on forum maintenance. ;-)