This example is on the strncpy() webpage but it is as follows:
/* strncpy example */
//strncpy(destination,source,number)
#include <stdio.h>
#include <string.h>
int main ()
{
char str1[]= "To be or not to be";
char str2[6];
strncpy (str2,str1,5);
//str2[6] = "to be or not to"
str2[5]='\0';
//str2[6] = "to be or not \0"
puts (str2);
return 0;
}
the comments are added by me for my logic. the output states that it should be "to be" but when i go through it myself, it reads "to be or not". why should the "or not" be taken out of str2?