• 当其他地方需要使用变量时,需要将变量定义在函数外,供其他函数使用


    1.局部变量,仅本函数使用,如下的变量preseluseres:

    submit_revisions()
    {
        char *preseluser,preseluseres[30];  //定义字符变量preseluser,用来表示预选用户,其中变量preseluseres作为preseluser的跳板,直接引用preseluser,就会成为一个常量
                                            //定义字符串变量preseluseres,字符串长度为30
        char *preselusertwo,preselusertwoes[30]; 
                                
        preseluser=lr_paramarr_random("selectusers");    //使用lr_paramarr_random函数随机获取selectusers列表中任意一项作为字符变量preseluser的值
        preselusertwo = lr_paramarr_random("selectusers");   //随机获取selectusers列表中任意一项作为字符串变量preselusertwo的值
        lr_output_message("preseluser=%s",preseluser);   //打印preseluser的值
        lr_output_message("preselusertwo=%s",preselusertwo);   //打印preselusertwo的值
        
        while(1)
        {
            if(preselusertwo==preseluser)
            {
                preselusertwo = lr_paramarr_random("selectusers");  //重新随机获取值
                lr_output_message("preselusertwo=%s",preselusertwo);   //打印preselusertwo的值
            }
            else
                break;  //否则退出循环
        }
        
        
        sprintf(preseluseres,"Value=%s",preseluser);  //使用sprintf函数,将"Value=%s"作为变量preseluseres的值
        lr_output_message("preseluseres=%s",preseluseres);   //打印preseluseres的值,验证preseluseres值是否正确,真正运行时可以把此行注释掉
    
        web_submit_data("add", 
            "Action=http://192.168.1.102:8000/reversion/revision/add/", 
            "Method=POST", 
            "EncType=multipart/form-data", 
            "RecContentType=text/html", 
            "Referer=http://192.168.1.102:8000/reversion/revision/add/", 
            "Snapshot=t6.inf", 
            "Mode=HTML", 
            ITEMDATA, 
            "Name=csrfmiddlewaretoken", "Value={addrevisionscsrfmiddlewaretoken}", ENDITEM, 
            "Name=csrfmiddlewaretoken", "Value={addrevisionscsrfmiddlewaretoken}", ENDITEM, 
            "Name=date_created_0", "Value={DateParame}", ENDITEM, 
            "Name=date_created_1", "Value={HourMinParam}", ENDITEM, 
            "Name=user", preseluseres, ENDITEM,    //引用preseluseres的值
            "Name=comment", "Value=123", ENDITEM, 
            "Name=version_set-TOTAL_FORMS", "Value=0", ENDITEM, 
            "Name=version_set-INITIAL_FORMS", "Value=0", ENDITEM, 
            "Name=version_set-MIN_NUM_FORMS", "Value=0", ENDITEM, 
            "Name=version_set-MAX_NUM_FORMS", "Value=1000", ENDITEM, 
            "Name=version_set-__prefix__-revision", "Value=", ENDITEM, 
            "Name=version_set-__prefix__-object_id", "Value=", ENDITEM, 
            "Name=version_set-__prefix__-content_type", "Value=", ENDITEM, 
            "Name=version_set-__prefix__-db", "Value=", ENDITEM, 
            "Name=version_set-__prefix__-format", "Value=", ENDITEM, 
            "Name=version_set-__prefix__-serialized_data", "Value=", ENDITEM, 
            "Name=version_set-__prefix__-object_repr", "Value=", ENDITEM, 
            "Name=version_set-__prefix__-id", "Value=", ENDITEM, 
            "Name=_save", "Value=", ENDITEM, 
            EXTRARES, 
            "Url=/static/xadmin/vendor/font-awesome/fonts/fontawesome-webfont.eot?", "Referer=http://192.168.1.102:8000/reversion/revision/", ENDITEM, 
            LAST);
    
        return 0;
    }

    2.其他地方也需要使用时,如下变量preseluseres,之后其他函数中也可以使用变量preseluseres:

    char preseluseres[30];
    
    submit_revisions()
    {
        char *preseluser;  //定义字符变量preseluser,用来表示预选用户,其中变量preseluseres作为preseluser的跳板,直接引用preseluser,就会成为一个常量
                                            //定义字符串变量preseluseres,字符串长度为30
        char *preselusertwo,preselusertwoes[30]; 
                                
        preseluser=lr_paramarr_random("selectusers");    //使用lr_paramarr_random函数随机获取selectusers列表中任意一项作为字符变量preseluser的值
        preselusertwo = lr_paramarr_random("selectusers");   //随机获取selectusers列表中任意一项作为字符串变量preselusertwo的值
        lr_output_message("preseluser=%s",preseluser);   //打印preseluser的值
        lr_output_message("preselusertwo=%s",preselusertwo);   //打印preselusertwo的值
        
        while(1)
        {
            if(preselusertwo==preseluser)
            {
                preselusertwo = lr_paramarr_random("selectusers");  //重新随机获取值
                lr_output_message("preselusertwo=%s",preselusertwo);   //打印preselusertwo的值
            }
            else
                break;  //否则退出循环
        }
        
        
        sprintf(preseluseres,"Value=%s",preseluser);  //使用sprintf函数,将"Value=%s"作为变量preseluseres的值
        lr_output_message("preseluseres=%s",preseluseres);   //打印preseluseres的值,验证preseluseres值是否正确,真正运行时可以把此行注释掉
    
        web_submit_data("add", 
            "Action=http://192.168.1.102:8000/reversion/revision/add/", 
            "Method=POST", 
            "EncType=multipart/form-data", 
            "RecContentType=text/html", 
            "Referer=http://192.168.1.102:8000/reversion/revision/add/", 
            "Snapshot=t6.inf", 
            "Mode=HTML", 
            ITEMDATA, 
            "Name=csrfmiddlewaretoken", "Value={addrevisionscsrfmiddlewaretoken}", ENDITEM, 
            "Name=csrfmiddlewaretoken", "Value={addrevisionscsrfmiddlewaretoken}", ENDITEM, 
            "Name=date_created_0", "Value={DateParame}", ENDITEM, 
            "Name=date_created_1", "Value={HourMinParam}", ENDITEM, 
            "Name=user", preseluseres, ENDITEM,    //引用preseluseres的值
            "Name=comment", "Value=123", ENDITEM, 
            "Name=version_set-TOTAL_FORMS", "Value=0", ENDITEM, 
            "Name=version_set-INITIAL_FORMS", "Value=0", ENDITEM, 
            "Name=version_set-MIN_NUM_FORMS", "Value=0", ENDITEM, 
            "Name=version_set-MAX_NUM_FORMS", "Value=1000", ENDITEM, 
            "Name=version_set-__prefix__-revision", "Value=", ENDITEM, 
            "Name=version_set-__prefix__-object_id", "Value=", ENDITEM, 
            "Name=version_set-__prefix__-content_type", "Value=", ENDITEM, 
            "Name=version_set-__prefix__-db", "Value=", ENDITEM, 
            "Name=version_set-__prefix__-format", "Value=", ENDITEM, 
            "Name=version_set-__prefix__-serialized_data", "Value=", ENDITEM, 
            "Name=version_set-__prefix__-object_repr", "Value=", ENDITEM, 
            "Name=version_set-__prefix__-id", "Value=", ENDITEM, 
            "Name=_save", "Value=", ENDITEM, 
            EXTRARES, 
            "Url=/static/xadmin/vendor/font-awesome/fonts/fontawesome-webfont.eot?", "Referer=http://192.168.1.102:8000/reversion/revision/", ENDITEM, 
            LAST);
    
        return 0;
    }
  • 相关阅读:
    java忽略安全警告注解@SuppressWarnings
    spring data jpa 报for input String "id"错误解决
    spring Data Jpa 报错 failed to lazily initialize a collection of role: com.itheim.pojo.Role.users, could not initialize proxy
    记一次Content type 'application/json;charset=UTF-8' not supported解决方案
    包冲突异常 loader constraint violation: when resolving interface method "javax.servlet.jsp.JspApplicationContext.getExpressionFacto
    Java运算符(&)、(|)、(^)、(~)
    Java中的原码、补码、反码
    vim编辑器
    Linux yum、tar、rpm、zip、gzip命令的使用
    error Couldn't find a package.json file in
  • 原文地址:https://www.cnblogs.com/jingzaixin/p/13629052.html
Copyright © 2020-2023  润新知