C Tutorial/string.h/strncpy — различия между версиями

Материал из C\C++ эксперт
Перейти к: навигация, поиск
м (1 версия: Импорт контента...)
 
(нет различий)

Текущая версия на 13:32, 25 мая 2010

strncpy

Item Value Header file string.h Declaration char *strncpy(char *str1, const char *str2, size_t count); Function copies up to count characters from *str2 to *str1. Return returns a pointer to str1.

  1. str2 must be a pointer to a null-terminated string.
  2. If *str2 has less than "count" characters, nulls will be appended to *str1 until count characters have been copied.
  3. If *str2 is longer than count characters, the result *str1 will not be null terminated.


<source lang="cpp">#include<stdio.h>

  1. include<string.h>

int main(void){

 char str1[128], str2[80];
 gets(str1);
 strncpy(str2, str1, 79);
 printf("%s",str2);

}</source>