• c语言中strncat函数、函数原型、头文件


    1、函数原型

    #include <stdio.h>
    
    char *strncat(char *s1, const char *s2, size_t n)
    {
        char *tmp = s1;
        
        while(*s1)
            s1++;
        
        while(n--)
        {
            if(!(*s1++ = *s2++))
                break;
        }
        *s1 = '';
        return tmp;
    }
    
    int main(void)
    {
        char str1[128] = "abcd";
        char str2[128];
        printf("str2: "); scanf("%s", str2);
        unsigned n;
        printf("n = "); scanf("%u", &n);
        
        strncat(str1, str2, n);
        
        printf("concatenate result: %s
    ", str1);
        return 0;
    }

    2、头文件

    #include <stdio.h>
    #include <string.h>
    
    int main(void)
    {
        char str1[128] = "abcd";
        char str2[128];
        printf("str2: "); scanf("%s", str2);
        
        unsigned n;
        printf("n = "); scanf("%u", &n);
        
        strncat(str1, str2, n);
        
        printf("concatenate result: %s
    ", str1);
        return 0;
    }

  • 相关阅读:
    PKU 1860 Currency Exchange 最短路 bellman
    PKU 3259 Wormholes 最短路 bellman
    bzoj3514
    bzoj2594
    bzoj3901
    bzoj2843&&1180
    bzoj2631
    bzoj2049
    bzoj2002
    bzoj1146
  • 原文地址:https://www.cnblogs.com/liujiaxin2018/p/14844038.html
Copyright © 2020-2023  润新知