I wrote the following thinking that "Arthur" would be cut when copied into dest as dest has only 4 spaces.
Why didn't it work that way?
main()
{
int i;
char source[]="Arthur";
char dest[3];
strncpy(dest, source, sizeof(source));
printf("Dest is now:%s\n", dest);
for (i=0; i>6; i++)
printf("%c", dest);
return 0;
}
the output is:
Dest is now:Arthur
Press any key to continue
Why didn't it work that way?
main()
{
int i;
char source[]="Arthur";
char dest[3];
strncpy(dest, source, sizeof(source));
printf("Dest is now:%s\n", dest);
for (i=0; i>6; i++)
printf("%c", dest);
return 0;
}
the output is:
Dest is now:Arthur
Press any key to continue