Saturday 4 February 2017

Few Basic C programs in Loadrunner


Q: which one will be printed in LR o/p
  1. printf(“Hello World”);
  2. lr_output_message(“Hello World);
Answer: Both will be printed if log is enabled else only 2nd will be printed
Q . write c  code to sum two number and print it on console
Int i=0;
Int j=5;
Int sum =i +j;
lr_output_message(“the sum of two number is %d” ,sum);

Q. Write c code to print a string variable in loadrunner
char str[] ="hello"
lr_output_message(%s, str);

Q. Write c code to copy a string to another string and print in loadrunner
char str1[] = "Hello World" ;
char str2[30] ;

strcopy(str2,str1);
lr_output_message("New string is %s", str2);

Q. write code to merge two string in loadrunner using c
char str1[] = "Hello World" ;
char str2[30] ;
strncopy(str2,str1,5);
lr_output_message("New string is %s", str2);

Q. write code copy part of string and print it in loadrunner using c

char str1[] = "Hello" ;
char str2[] =”World”
strcat(str1,str2);
lr_output_message("New string is %s", str1);

Q. write code to find length of c string variable and print in lr ?

char str1[] = "Hello" ;

lr_output_message("New string is %s", strlen(str1));

Q write code to find first and last occurrence of a character in  given string ?

char str1[] = "Hello World" ;
char * first;
char * last;

//finding first occurance of o

first = (char *) strchr(str1, 'o');
lr_output_message(first);

last = (char *) strrchr(str1, 'o');

Q write code to find first occurrence of a string in  given string ?

char str1[] = "I am a leader but i am not a boss” ;
char search[] = "am" ;
char * postion ;
int offset ;

position = (char *) strstr(str1, search);
offset = (int) (position - str +1)
lr_output_message(" first occurrence of search string is at %d ", offset);

Q. Which function is used to compare two string
Ans: strcmp

No comments:

Post a Comment