Copy characters from one string to another: how to use strncpy
#include <stdio.h> #include <string.h> int main () { char str1[]= "Hi Hello and "; char str2[6]; strncpy (str2, str1, 5); str2[5] = '\0'; puts (str2); return 0; }