0

This code should copy a source string to a target string. I believe that my code is correct, however if the source string contains exactly 4 characters, the resulting target string contains one additional character, namely "╔". Why does this happen? Thanks in advance.

#include <stdio.h>


void copyString(char* target, char* source){
    int i = 0;
    while(*(source + i) != '\0') {
        *(target + i) = *(source + i);
        i++;
    }
    for (int j = 0; j <= i; j++){
        printf("%c", *(target + j));
    }
}
int main (){
    char source[1001];
    char target[1001];

    printf("Please enter a source string: \n");
    scanf("%s", &source);

    copyString(target, source);
}

Input: aaaa
Output: aaaa╔

Input: aaaaa
Output: aaaaa (without the character(╔)

0 Answers0