LoadRunner中常用的C语言函数

函数名:strcat

功能:字符串拼接

函数定义:char *strcat( char *to, const char *from);

    char fullpath[1024], * filename = "logfile.txt"; 

    strcpy(fullpath, "c:\\tmp"); 

    strcat(fullpath, "\\"); 

    strcat(fullpath, filename); 

    lr_output_message ("Full path of file is %s", fullpath); 

    Output:
    Action.c(9): Full path of file is c:\tmp\logfile.txt

函数名:strcmp

功能:两个字符串比较

函数定义:int strcmp( const char *string1, const char *string2);

  int result; 

  char tmp[20]; 

  char string1[] = "The quick brown dog jumps over the lazy fox"; 

  char string2[] = "The QUICK brown dog jumps over the lazy fox"; 

  result = strcmp( string1, string2); // Case-sensitive comparison 

  if(result > 0) 

      strcpy(tmp, "greater than"); 

  else if(result < 0) 

      strcpy(tmp, "less than"); 

  else 

      strcpy(tmp, "equal to"); 

  lr_output_message ("strcmp: String 1 is %s string 2", tmp); 

  result = stricmp(string1, string2 ); // Case-insensitive comparison 

  if( result > 0 ) 

      strcpy( tmp, "greater than" ); 

  else if( result < 0 ) 

      strcpy( tmp, "less than" ); 

  else 

      strcpy( tmp, "equal to" ); 

  lr_output_message( "stricmp: String 1 is %s string 2", tmp ); 

Output:
Action.c(17): strcmp: String 1 is greater than string 2
Action.c(28): stricmp: String 1 is equal to string 2
返回值 描述
<0 string1 小于string2
0 string1 等于string2
>0 string1 大于string2

函数名:strcpy

功能:将一个字符串复制到另一个字符串

函数定义:char *strcpy( char *dest, const char *source);

 char fullpath[1024], * filename = "logfile.txt"; 

 strcpy(fullpath, "c:\\tmp"); 

 lr_output_message ("fullpath after strcpy: %s", fullpath); 

 strcat(fullpath, "\\"); 

 strcat(fullpath, filename); 

 lr_output_message ("Full path of file is %s", fullpath);} 

Output:
Action.c(6): fullpath after strcpy: c:\tmp
Action.c(10): Full path of file is c:\tmp\logfile.txt 

函数名:strlen

功能:返回指定字符串的长度

函数定义:size_t strlen( const char *string ); 

 int is_digit, i = 0; 

 char * str = "1234567k89"; 

 unsigned int len = strlen(str); 

 do { 

     if (i == len) { 

         lr_output_message ("No letters found in string"); 

         return -1; 

     } 

     is_digit = isdigit(str[i++]); 

 } while (is_digit); 

 lr_output_message ("The first letter appears in character %d of string", i);} 

Output:
Action.c(18): The first letter appears in character 8 of string<strong>
</strong>


你可能感兴趣的:(C语言,loadrunner)