strncpy.c

来自「c21Examples.rar」· C语言 代码 · 共 30 行

C
30
字号
/* Using the strncpy() function. */

#include <stdio.h>
#include <string.h>

char dest[] = "..........................";
char source[] = "abcdefghijklmnopqrstuvwxyz";

int main( void )
{
    size_t n;

    while (1)
    {
        puts("Enter the number of characters to copy (1-26)");
        scanf("%d", &n);

        if (n > 0 && n< 27)
            break;
    }

    printf("\nBefore strncpy destination = %s", dest);

    strncpy(dest, source, n);

    printf("\nAfter strncpy destination = %s\n", dest);
    return 0;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?