zoukankan      html  css  js  c++  java
  • c语言中strcat函数,函数原型和函数头文件

    1、函数原型

    #include <stdio.h>
    
    char *strcat(char *s1, const char *s2) //函数返回类型为指针,形参为两个指针(为字符串数组的数组名,相当于指向数组第一个元素的指针) 
    {
        char *tmp = s1;  //将指针tmp赋值为s1指针,也就是指向字符串数组*s1第一个字符的指针 
        while(*s1) 
            s1++;  // 指针s1从指向字符串数组第一个元素逐渐递增到指向字符串数组末尾的null的空指针。 
        while(*s1++ = *s2++)  // 从指针s1当前的位置开始,字符串数组s2的元素一次复制给字符串s1,直到s2指针指向null。 
            ;
        return tmp;  // 返回指针tmp,指向字符串数组*s1第一个元素的指针 
    }
    
    int main(void)
    {
        char str1[128] = "abcdefg";
        char str2[128] = "123456789";
        
        printf("concatenate result: %s
    ", strcat(str1, str2)); // 函数传输字符串数组名,相当于指向数组第一个元素的指针。 
        return 0;
    }

    2、加载strcat函数的头文件<string.h>,可以直接调用strcat函数

    #include <stdio.h>
    #include <string.h>  // strcat函数的头文件 
    
    int main(void)
    {
        char str1[128] = "abcd";
        char str2[128] = "1234";
        
        printf("concatenate result: %s
    ", strcat(str2, str1)); // 函数调用时给与的实参是字符串数组名,相当于指向数组第一个元素的指针。 
        return 0;
    } 

  • 相关阅读:
    GXPT(一)——UI设计
    JVM系列文章(四):类载入机制
    poj 2688 状态压缩dp解tsp
    ASP.NET MVC Model绑定(四)
    cocos2dx实例开发之flappybird(入门版)
    qt creator中使用qwt插件
    [CodeEdit--Sublime]一些好用的Plugins
    NBUT 1225 NEW RDSP MODE I
    [IOC]Unity使用
    [Js/Jquery]jquery插件开发
  • 原文地址:https://www.cnblogs.com/liujiaxin2018/p/14836009.html
Copyright © 2011-2022 走看看