You need to proper terminate the strings in both your Caesar_encrypt()
and Caesar_decrpyt()
functions.
C strings are terminated with a single '\0'
character, so you can add this line before the return 0;
at the bottom of the aforementioned function bodies:
....
// Terminate the string, adding a \0
*(s+i) = '\0';
return 0;
}
BTW: I prefer using the array syntax s[i]
to identify single characters in strings, so I'd do s[i] = 0;
.
Moreover, you may want to use const
to mark the input (read-only) strings in your function signatures (and update function definitions as well):
int Caesar_encrypt(const char *p, char *s, int enckey);
int Caesar_decrypt(const char *p, char *s, int enckey);