User Tools

Site Tools


Sidebar

Programming Reference/Librarys

Question & Answer

Q&A is closed







c:string.h:strncpy

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 

on the occasion of the current invasion of Russia in Ukraine

Russian Stop this War
c/string.h/strncpy.txt · Last modified: 2024/02/16 01:06 (external edit)

Impressum Datenschutz