Floating point numbers multiplication in LoadRunner
I have written this code to multiply 2 floating point numbers and then saving it into a parameter:
I'm getting this error message: Action.c(14): Error: C interpreter run time error: Action.c (14): Error -- memory violation : Exception ACCESS_VIOLATION received.
Line 14: sprintf(result,"%2f",decimals);
Any inputs/suggestions are highly welcome.
Thanks in advance,
Re: Floating point numbers multiplication in LoadRunner
There are a couple of issues here:
1. If you want to use a function that do not return an Integer, it needs to be declared first. This means that you need to put the following line as first in vuser_init, as it is now, it multiplies the adresses of the strings. Also atof() returns only the integer part, even if you assign it to a double.
double atof( const char *string);
Next, sprintf() takes as first parameter a character buffer where the result to be written. now you printing somewhere random in memmory and gets an error.
So what is it that you want to accomplish? Multiply two LoadRunner parameters (as floating point) and save the result to new LoadRunner parameter, with 2 decimals?
Please mark post as solved if your problems or questions is/are resolved.
If this post was valuable to you, please consider kudo it.
Re: Floating point number multiplication in LoadRunner
You need to program to C99 Standards, the return type must be declared as int.
Where do you include <stdio.h> and <stdlib.h>? result and finalOutput aren't char arrays.
>If you want to use a function that does not return an Int, it needs to be declared first.
That's not correct. If you want to use ANY function you must declare it first. 😉
You also shouldn't be making up declarations but should be including the standard C headers:
<stdio.h> & <stdlib.h>