无法在loadrunner中打印字符数组

时间:2018-07-07 15:40:56

标签: c loadrunner

我试图从LR参数中读取一个字符串并逐个字符地打印它,但是不知何故,LR正在渲染垃圾字符。有人可以检查我的代码吗?

char str1[]="";
int len = 0;
int i =0;
char temp[]="";
sprintf(str1,"%s",lr_eval_string("{input}"));
lr_output_message("The message i got is %s",str1);

len=strlen(str1);
lr_output_message("The length of the message is- %d",len);

while(str1[i]!='\0')
{
    lr_output_message("Here is value being read %c",str1[i]);

    temp[0]=str1[i];
    temp[1]='\0';
    lr_output_message("Here is the value of temp -%s",temp);

    temp[0]='\0';
    i++;
}

以下是输出:

Starting action Action.
Action.c(8): The message i got is testing
Action.c(12): The length of the message is- 7
Action.c(17): Here is value being read t
Action.c(21): Here is the value of temp -t
Action.c(17): Here is value being read e
Action.c(21): Here is the value of temp -e
Action.c(17): Here is value being read s
Action.c(21): Here is the value of temp -s
Action.c(17): Here is value being read 
Action.c(21): Here is the value of temp -

1 个答案:

答案 0 :(得分:0)

设法删除了初始化部分并调整了大小后解决了该问题。 这是更新的代码。

char str1[10];
int len = 0;
int i =0;
char temp[10];
sprintf(str1,"%s",lr_eval_string("{input}"));
lr_output_message("The message i got is %s",str1);

len=strlen(str1);
lr_output_message("The length of the message is- %d",len);

while(str1[i]!='\0')
{
    lr_output_message("Here is value being read %c",str1[i]);

    temp[0]=str1[i];
    temp[1]='\0';
    lr_output_message("Here is the value of temp -%s",temp);

    temp[0]='\0';
    i++;
}