gpt4 book ai didi

c - 无法在 loadrunner 中打印字符数组

转载 作者:行者123 更新时间:2023-11-30 16:30:19 25 4
gpt4 key购买 nike

我试图从 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 -

最佳答案

在删除初始化部分并分配大小后成功解决了这个问题。这是更新后的代码。

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++;
}

关于c - 无法在 loadrunner 中打印字符数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51224632/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com