User Tools

Site Tools


Sidebar

Programming Reference/Librarys

Question & Answer

Q&A is closed







c:string.h:strncpy
click
to support this page (eg 0,42 € or so) Thanks.

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 
advertising
c/string.h/strncpy.txt · Last modified: 2013/02/17 01:55 by Daniel Gohlke

Impressum