0

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.
Sakura
  • 869
  • 4
  • 13
  • 32
  • All I can say is that in `strcpy(string1,string2);` the contents of string2 is assigned to string1 so the string in string2 remains unaffected. – 0decimal0 Jun 27 '13 at 04:50

3 Answers3

0

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?

Community
  • 1
  • 1
0decimal0
  • 3,884
  • 2
  • 24
  • 39
  • Hi. I tried that but it is not working. Any ideas why is it not working? – Sakura Jun 27 '13 at 07:40
  • This statement should work as far as its syntax is concerned,you will have to provide whole code so that improvements can be made and you should also try by yourself to find mistakes in other part. – 0decimal0 Jun 27 '13 at 07:45
  • I have provided the link in the answer. – 0decimal0 Jun 27 '13 at 07:48
  • Ihave edited my original post with the code. It doesn't seems to work. – Sakura Jun 27 '13 at 09:11
  • I think you are allocating a huge size for character array and that is a bad practice. But unless you show the whole code,I mean what is the size of the parameter `c_response` its almost impossible to tell what is going wrong.May be size of `c_response` could be more than size of `str`. – 0decimal0 Jun 27 '13 at 11:30
  • I just realised that my `c_Response` is bigger than `str`. I have increased it to 5000. The `c_Response` is a dynamic variable that is passed from the web server directly so I am not sure how to get the size of `c_Response`. – Sakura Jun 28 '13 at 01:50
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/32534/discussion-between-phifounder-and-sakura) – 0decimal0 Jun 28 '13 at 04:01
0

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);
0

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.

James Pulley
  • 5,606
  • 1
  • 14
  • 14
  • As you are new to LoadRunner and C, set LoadRunner aside for a time and learn C. Having expertise in the language of your test tool is really a prerequisite to being successful, whether that is C with LoadRunner, Pascal with SilkPerfomer, or Java with Jmeter. Trying to learn foundation skills at the same time as your line of business skills is as sure a path to failure in the role as exists, independent of whether that role is as a performance tester or anything else. – James Pulley Jul 03 '13 at 19:17