loadrunner出现报错operands of = have illegal types `pointer to char' and `int'

版权声明:编写不易,可看不可转,请知悉! https://blog.csdn.net/zha6476003/article/details/85240407

原始代码:

void split(char * p,char * str){
	/*
		传入一个数组进行p和一个以什么进行分割的str,返回切片后的值
	*/ 
	
	int i = 0, j = 0;
    char tmp[32][32] = {0};
    char *p1 = (char *)malloc(1024);
 
    while((p1 = strchr(p, *str)) != NULL) //10行
    {
        strncpy(tmp[i], p, strlen(p) - strlen(p1));
        p = p1 + 1;
        i ++;
    }
    strncpy(tmp[i], p, strlen(p));
 
    for(j = 0; j <= i; j++){
		lr_output_message("tmp[%d] = %s\n", j, tmp[j]);
	}
}
 
Action (){

	char p[] = "www.baidu.com,www.taobao.com,www.csdn.com,www.python.org";
	char str[] = ","; //分割的字符串 
    split(p,str);
 
    return 0;
}

运行后第10行出现指针报错:operands of = have illegal types `pointer to char’ and `int’ ,百思不得其解,dev-C++中运行一切正常,各种排查后发现传参确实符合要求,第10行给指针变量赋值时未对strchr返回的值进行强制类型转换(等于直接给指针变量赋值(太粗心了-_-!!))

修改后脚本:

void split(char * p,char * str){
	/*
		传入一个数组进行p和一个以什么进行分割的str,返回切片后的值
	*/ 
	
	int i = 0, j = 0;
    char tmp[32][32] = {0};
    char *p1 = (char *)malloc(1024);
 
    while((p1 = (char *)strchr(p, *str)) != NULL) //必须使用(char *)进行强制类型转换
    {
        strncpy(tmp[i], p, strlen(p) - strlen(p1));
        p = p1 + 1;
        i ++;
    }
    strncpy(tmp[i], p, strlen(p));
 
    for(j = 0; j <= i; j++){
		lr_output_message("tmp[%d] = %s\n", j, tmp[j]);
	}
}
 
Action (){

	char p[] = "www.baidu.com,www.taobao.com,www.csdn.com,www.python.org";
	char str[] = ","; //分割的字符串 
    split(p,str);
 
    return 0;
}
loadrunner中执行结果:
	Starting iteration 1.
	Starting action Action.
	Action.c(19): tmp[0] = www.baidu.com
	Action.c(19): tmp[1] = www.taobao.com
	Action.c(19): tmp[2] = www.csdn.com
	Action.c(19): tmp[3] = www.python.org
	Ending action Action.
	Ending iteration 1.

猜你喜欢

转载自blog.csdn.net/zha6476003/article/details/85240407