您好,欢迎来到华拓科技网。
搜索
您的当前位置:首页pta c语言 6-3 M07-字符串-连接

pta c语言 6-3 M07-字符串-连接

来源:华拓科技网

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

函数接口定义:

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

在这里解释接口参数。例如:其中 s 是用户传入的第一个参数,是要进行连接操作时的第一个字符串; t 也是用户传入的参数,是连接操作时的第二个字符串(要连接在右边的字符串)。

函数功能:将指针s指向空间中的字符串,和指针t所指向空间中的字符串,连接起来后,以指针的形式返回连接后的字符串。

裁判测试程序样例:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define MAX 100

//将s和t指向的字符串连接起来,作为函数返回值 
char *str_cat(char *s, char *t);

int main()
{
    char *p;
    char str1[MAX+MAX] , str2[MAX];
    scanf("%s%s", str1, str2);
    p = str_cat(str1, str2);
    printf("%s", p);
    return 0;
}

/* 请在这里填写答案 */

输入样例:

在这里给出一组输入。例如:

Hello  World

输出样例:

在这里给出相应的输出。例如:

HelloWorld

正确答案:

char *str_cat(char *s, char *t)
{
    char*ps;
    ps=s;
    int count=0;
    for(int i=0;*ps!='\0';ps++);
    while(*t!='\0')
    {
        *ps=*t;
        ps++;
        t++;
    }
    *ps='\0';
    return s;
}

因篇幅问题不能全部显示,请点此查看更多更全内容

Copyright © 2019- huatuo6.cn 版权所有 赣ICP备2024042791号-9

违法及侵权请联系:TEL:199 18 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务