Hello all, I've encountered something that obviously should not happen in C. I declared an array of characters of say length 10 and insert 12 characters into it and it works fine. Why does this happen?
Code:
#include <stdio.h>
char *myStrCpy(char*, char*);
int main()
{
char string[] = "Mary had a lamb.";
char copy[10] = "012345678";
*myStrCpy( copy, string );
printf("%s\n", copy);
}
char *myStrCpy( char dest[], char source[] )
{
int i = 0;
while ( source[i] != '\0' )
{
dest[i] = source[i];
i++;
}
dest[i] = '\0';
return dest;
}