• 第八周作业


    这个作业属于那个课程 C语言程序设计II
    这个作业要求在哪里 https://www.cnblogs.com/pengchen511/p/10564067.html
    我在这个课程的目标是 了解动态数组
    这个作业在哪个具体方面帮助我实现目标 知道了动态数组的使用
    参考文献 c语言程序设II

    函数实现字符串逆序:

    本题要求实现一个字符串逆序的简单函数。

    函数接口定义:

    void f( char *p );
    

    函数f对p指向的字符串进行逆序操作。要求函数f中不能定义任何数组,不能调用任何字符串处理函数。

    裁判测试程序样例:

    #include <stdio.h>
    #define MAXS 20
    
    void f( char *p );
    void ReadString( char *s ); /* 由裁判实现,略去不表 */
    
    int main()
    {
        char s[MAXS];
    
        ReadString(s);
        f(s);
        printf("%s
    ", s);
    
        return 0;
    }
    
    /* 你的代码将被嵌在这里 */
    

    输入样例:

    Hello World!
    

    输出样例:

    !dlroW olleH
    

    实验代码:

    void f( char *p ){
        int n=strlen(p)/2;
        int i,temp;
    
        for(i=0;i<n;i++){
            temp=p[i];
            p[i]=p[strlen(p)-i-1];
            p[strlen(p)-i-1]=temp;
        }
        return p;
    }
    

    字符串的连接:

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

    函数接口定义:

    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
    

    实验代码:

    char *str_cat( char *s, char *t ){
        strcat(s,t);
        return s;
    }
    
  • 相关阅读:
    css去掉点击连接时所产生的虚线边框技巧兼容符合w3c标准的浏览器
    html中<a href> </a>的用法
    点击页面其他地方关闭弹出层
    CSS文字两端对齐
    mouseover和mouseenter的区别
    jquery中的$("#id")与document.getElementById("id")的区别
    console.log
    ie6中margin失效问题
    渐变
    CSS 清除浮动的4种方法
  • 原文地址:https://www.cnblogs.com/tengziqiang/p/10737459.html
Copyright © 2020-2023  润新知