caesar cipher printing additional characters?

I have the basic functionality of the cipher down, but when for some reason, it's printing out additional characters at the end.

For example:
input: Hello world20
output: Lipps asvph20mD
shift #: 4

Where is that "mD" coming from?

1
2
3
4
5
6
7
for(int i = 0; i < strlen(cStr); i++) {
    if(isalpha(cStr[i]) {
        //shift
    } else {
        tmp[i] = cStr[i];
    }
}


It's probably the tmp[i] = cStr[i] line right? How do I avoid this problem and correctly shift only alphabet letters?
You're probably never copying the null terminator over to 'tmp'.

Remember that the null is how the computer knows it has reached the end of the string. Without it, it'll keep thinking there are more garbage characters following your string (like that mysterious 'mD')
Topic archived. No new replies allowed.