Copy characters from one string to another: how to use strncpy : String Copy « String « C / ANSI-C






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;
}

           
       








Related examples in the same category

1.how to use strcpy (string copy)
2.A simple string copy
3. Copy string: how to use strcpy
4.String copy: assign the pointer value
5.Copy a string