Hello when Im trying to learn strncpy function, I copied a part of string to another char array, but it gave me different results when I used puts and printf functions. Can anyone tell me why such difference occurs? I guess its about the last terminating NULL character, but Im not sure at all. Here is the code :
#include <stdio.h>
#include <string.h>
int main()
{
char a[] = "barbara dickens";
char b[8];
strncpy(b,a,7);
puts(b);
printf("%s", b);
return 0;
}
puts function prints barbara and printf function prints barbar,
Thanks