Question

I am new to HP Load Runner and is trying to convert an existing C code to be compatible with Load Runner. I have a array tempStr from Load Runner that I am trying to put its contents into char str[1024]. I tried using strcpy(lr_eval_string("{tempStr}"),str); but the contents in str is still empty. Does anyone know how I can put the contents of tempStr to str?

EDIT: My code is:

char str[1024];
strcpy(str,lr_eval_string("{c_Response}"));

I am getting the following errors:

Ccode.c(22): Error: C interpreter run time error: Ccode.c (22):  Error -- memory violation : Exception ACCESS_VIOLATION received.
Ccode.c(22): Error: An exception was raised while calling invocation function in interpreter extension cciext.dll: System Exceptions: EXCEPTION_ACCESS_VIOLATION.
Was it helpful?

Solution

In strcpy(string1,string2); the contents of string2 is assigned to string1.So if you want to put contents of character array tempStr in `str,you need to try this :

strcpy(str,lr_eval_string("{tempStr}"));.This should do the trick.You can see a related use of the statement over here.

You are declaring HUGE ARRAY ( char str[1024] ) OR the size of c_response could be more than str and this may be the reason why you are getting that error . Instead of that you can dynamically allocate memory by using malloc,which is a good practice and is considered safe.

(By looking at the code everything looks just fine so, again,unless you show the whole code its quite difficult to say).

Declaring very large arrays in C is very bad practice.Just take a look at this :How many chars can be in a char array?

OTHER TIPS

I have tested this and its working perfectly fine and there could be some other issue

char str[1024]="test";

lr_output_message("Value is %s", str);

strcpy(str,lr_eval_string("{NewParam}"));

lr_output_message("Value is %s", str);

You have a type mismatch, strcpy expects two pointers.

Action()
{

    char str[500]="";

    lr_save_string("abcdefg123456789","my_foo");

    strcpy((char *)str,lr_eval_string("{my_foo}")); 

    lr_message(str);

    return 0;
}

Run the above and see what happens. Understand why (char *) solves the problem before you go any further. This is an opportunity to shore up some foundation skills in 'C' that you will need to leverage now and in the future.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top