LR Scripting user-defined C-language functions

Source: Internet
Author: User
Tags uppercase character

LR Script Combat: User-defined C-language function LoadRunner can use standard C language functions, so we can write our own function in the script to call, the script structure, better reuse.  First look at an example: Action () {int i,j; j = 1; for (i=0;i<10;i++) {lr_message ("i+j=%d", Sum (i,j)); j + +; } return 0;} int sum (int a,int b)//simple Sum function {return a+b;} Example: I wrote a very simple function sum, 2 integers and 1, the function implementation can be placed anywhere in the LR script (scope of the function), such as action, Vuser_init, vuser_end the main functions of these scripts, you do not need to consider the scope of the function   ; can be called anywhere. If you put it in the function body of action (), Vuser_init (), Vuser_end (), only the body of this function can be called. For example: Action () {int a,int b)//simple Sum function {return a+b;} int i,j; j = 1; for (i=0;i<10;i++) {lr_message ("i+j=%d", s  Um (i,j)); j + +; } return 0;} In the example above, only the SUM function can be called inside the action. 2. If you want to jump out of a function, use return 0 or break to see an example of a slightly more complicated point: Action () {int aa[20]; Checkchar ("AaBbCc001 1 1", AA); Lr_message ("String length:%d", aa[0]); Lr_message ("Statistics-uppercase characters:%d", aa[1]); Lr_message ("Statistics-lowercase characters:%d", aa[2]); Lr_message ("Statistics-numeric characters:%d", aa[3]); Lr_message ("Statistics-space character:%d", aa[4]); return 0;}  void Checkchar (char ch[],int a[])//statistical functions, respectively, count the length of the string, the number of uppercase, lowercase, digits and spaces, return shaping is saved in the array {int i; for (i=0;i<=3;i++) a[i]=0; a[0] = strlen (CH);//Gets the string length for (i=0;i<a[0];i++) {if (ch[i]>= ' a ' && ch[i]<= ' Z ')//If it is an uppercase character a[1]++;  else if (ch[i]>= ' a ' && ch[i]<= ' z ')//if it is a lowercase character a[2]++;  else if (ch[i]>= ' 0 ' && ch[i]<= ' 9 ')//If it is a digital a[3]++; else if (ch[i]== ')//If it is a space a[4]++; }} wrote a function to check the string component, only the length of the string, uppercase, lowercase, number, and the number of spaces. Thus, the use of C functions in LR is more flexible.  Attach a pointer-related function call: Action () {int *i, *j;//*i = 100;  int a=50, b=50;  i = &a;  j = &b; Lr_message ("i+j=%d", Sum (i,j)); return 0;} int sum (int *a,int *b)//simple Sum function {return *a + *b;}

LR Scripting user-defined C-language functions

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.