c语言中strcat函数,函数原型、头文件


1、函数原型

#include <stdio.h>

char *strcat(char *s1, const char *s2)
{
    char *tmp = s1;
    
    while(*s1)
        s1++;
    
    while(*s1++ = *s2++)
        ;
    
    return tmp;
}

int main(void)
{
    char str1[128] = "abcd";
    char str2[128];
    
    printf("str2: "); scanf("%s", str2);
    strcat(str1, str2);
    
    printf("concatenate result: %s\n", 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);
    
    strcat(str1, str2);
    printf("concatenate result: %s\n", str1);
    return 0;
}

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM