当前位置:网站首页>Exercise 8-5 using functions to realize partial copying of strings (20 points)

Exercise 8-5 using functions to realize partial copying of strings (20 points)

2022-06-11 22:26:00 Xiaoyan y

This problem requires writing functions , The input string t From the first m Copy all characters starting with characters to the string s in .

Function interface definition :

void strmcpy( char *t, int m, char *s );

function strmcpy The input string char *t From the first m Copy all characters starting with characters to the string char *s in . if m Exceeds the length of the input string , The result string should be an empty string .

Sample referee test procedure :

#include <stdio.h>
#define MAXN 20

void strmcpy( char *t, int m, char *s );
void ReadString( char s[] ); /* By the referee , Omit no watch */

int main()
{
    char t[MAXN], s[MAXN];
    int m;

    scanf("%d\n", &m);
    ReadString(t);
    strmcpy( t, m, s );
    printf("%s\n", s);

    return 0;
}

/* Your code will be embedded here */

sample input :

7
happy new year

sample output :

new year

void strmcpy( char *t, int m, char *s ){
    int i;
    for(i=0;i<strlen(t);i++){
        s[i]=t[m-1];
        m++;
    }
}

 

原网站

版权声明
本文为[Xiaoyan y]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/162/202206112218444373.html