zoukankan      html  css  js  c++  java
  • C语言-C语言程序设计-Function-strcpy

    C语言-C语言程序设计-Function-strcpy

    书上关于strcpy介绍了数组、指针、指针简化的例子,对于代码简化是个可见的例子,记录下来。

    #include <stdio.h>
    #include <stdlib.h>
    
    int main()
    {
        //initial value
        char cTmp[] = "It will be better, tomorrow.";
        printf("cTmp:%s
    ", cTmp);
    
        char* pTmp =  "It will be better, tomorrow.";
        printf("pTmp:%s
    ", pTmp);
    
        char* pCon = malloc(100);
        memset(pCon, 0, sizeof(char));
        printf("pCon:%s
    ", pCon);
    
        //
        strcpy1(pCon, pTmp);
        printf("pCon1:%s
    ", pCon);
        memset(pCon, 0, sizeof(char));
        printf("pCon:%s
    ", pCon);
    
        strcpy2(pCon, pTmp);
        printf("pCon2:%s
    ", pCon);
        memset(pCon, 0, sizeof(char));
        printf("pCon:%s
    ", pCon);
    
        strcpy3(pCon, pTmp);
        printf("pCon3:%s
    ", pCon);
        memset(pCon, 0, sizeof(char));
        printf("pCon:%s
    ", pCon);
    
        strcpy4(pCon, pTmp);
        printf("pCon4:%s
    ", pCon);
        memset(pCon, 0, sizeof(char));
        printf("pCon:%s
    ", pCon);
    
        return 0;
    }
    
    
    void strcpy1(char *s, char *t)
    {
        int i = 0;
        while((s[i]=t[i]) != '')
            i++;
    }
    
    void strcpy2(char *s, char *t)
    {
        while((*s = *t) != '')
        {
            s++;
            t++;
        }
    }
    
    void strcpy3(char *s, char *t)
    {
        while((*s++ = *t++) != '');
    }
    
    void strcpy4(char *s, char *t)
    {
        while(*s++ = *t++);
    }
    
    
  • 相关阅读:
    Pikachu-File Inclusion模块
    Pikachu-RCE模块
    Pikachu-CSRF模块
    Pikachu-暴力破解模块
    Pikachu-XSS模块与3个案例演示
    将Word文档发布至博客园随笔
    DVWA-全等级XSS(反射型、存储型)
    DVWA-sql注入(盲注)
    DVWA-全等级验证码Insecure CAPTCHA
    管理页面的 setTimeout & setInterval
  • 原文地址:https://www.cnblogs.com/yongchao/p/13972554.html
Copyright © 2011-2022 走看看