zoukankan      html  css  js  c++  java
  • 习题11-4 字符串的连接(15 分)

    本题要求实现一个函数,将两个字符串连接起来。

    函数接口定义:

    char *str_cat( char *s, char *t );
    

    函数str_cat应将字符串t复制到字符串s的末端,并且返回字符串s的首地址。

    裁判测试程序样例:

    #include <stdio.h>
    #include <string.h>
    
    #define MAXS 10
    
    char *str_cat( char *s, char *t );
    
    int main()
    {
        char *p;
        char str1[MAXS+MAXS] = {''}, str2[MAXS] = {''};
    
        scanf("%s%s", str1, str2);
        p = str_cat(str1, str2);
        printf("%s
    %s
    ", p, str1);
    
        return 0;
    }
    
    /* 你的代码将被嵌在这里 */
    

    输入样例:

    abc
    def
    

    输出样例:

    abcdef
    abcdef
    
    /*函数str_cat应将字符串t复制到字符串s的末端,并且返回字符串s的首地址。*/
    char *str_cat( char *s, char *t )
    {
        char *p;
        p=strcat(s,t);//函数strcat的功能是把两个字符串连接成一个字符串 
        return p;
    }

    char string2[100]="csdn ";

    char string3="wo ai ni";

    char *string1=strcat(sting2,string3);

    printf("s ",string1);//将会输出csdn wo ai ni

    printf("s ",string2);//将会输出csdn wo ai ni

    printf("s ",string3);//将会输出wo ai ni

  • 相关阅读:
    HDU 4334
    HDU 1280
    HDU 1060
    HDU 4033
    大三角形分成4个面积相等的小三角形
    HDU 1087
    HDU 4313
    Sleep(0)及其使用场景
    Decorator(装饰、油漆工)对象结构型模式
    Debug Assertion Failed!
  • 原文地址:https://www.cnblogs.com/2228212230qq/p/9275456.html
Copyright © 2011-2022 走看看