strncpy

#include <string.h>
char *strncpy(char *str1, const char *str2, size_t n);

Copy a given Number of Chars into another string.

#include <stdio.h> /* including standard library */
//#include <windows.h> /* uncomment this for Windows */
 
#include <string.h>
#define MAX 5
 
int main( void )
{
    char string1[MAX];
    char string2[]="Test 12345";
 
    strncpy(string1, string2, MAX);     /* Copy MAX chars from string2 to string1 */
    string1[MAX]='\0';                  /* Terminate String */
    printf("string1 %s\n",string1);
return 0;
}

Output:

  user@host:~$ ./strncpy 
  string1 Test