LoadRunner中常用的C语言函数

函数名:strcat

功能:字符串拼接

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

[csharp]  view plain  copy
  1. char fullpath[1024], * filename = "logfile.txt";   
  2.   
  3. strcpy(fullpath, "c:\\tmp");   
  4.   
  5. strcat(fullpath, "\\");   
  6.   
  7. strcat(fullpath, filename);   
  8.   
  9. lr_output_message ("Full path of file is %s", fullpath);   
  10.   
  11. Output:  
  12. Action.c(9): Full path of file is c:\tmp\logfile.txt  

函数名:strcmp

功能:两个字符串比较

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

[csharp]  view plain  copy
  1.   int result;   
  2.   
  3.   char tmp[20];   
  4.   
  5.   char string1[] = "The quick brown dog jumps over the lazy fox";   
  6.   
  7.   char string2[] = "The QUICK brown dog jumps over the lazy fox";   
  8.   
  9.   result = strcmp( string1, string2); // Case-sensitive comparison   
  10.   
  11.   if(result > 0)   
  12.   
  13.       strcpy(tmp, "greater than");   
  14.   
  15.   else if(result < 0)   
  16.   
  17.       strcpy(tmp, "less than");   
  18.   
  19.   else   
  20.   
  21.       strcpy(tmp, "equal to");   
  22.   
  23.   lr_output_message ("strcmp: String 1 is %s string 2", tmp);   
  24.   
  25.   result = stricmp(string1, string2 ); // Case-insensitive comparison   
  26.   
  27.   if( result > 0 )   
  28.   
  29.       strcpy( tmp, "greater than" );   
  30.   
  31.   else if( result < 0 )   
  32.   
  33.       strcpy( tmp, "less than" );   
  34.   
  35.   else   
  36.   
  37.       strcpy( tmp, "equal to" );   
  38.   
  39.   lr_output_message( "stricmp: String 1 is %s string 2", tmp );   
  40.   
  41. Output:  
  42. Action.c(17): strcmp: String 1 is greater than string 2  
  43. Action.c(28): stricmp: String 1 is equal to string 2  
返回值描述
<0string1 小于string2
0string1 等于string2
>0string1 大于string2

函数名:strcpy

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

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

[csharp]  view plain  copy
  1.  char fullpath[1024], * filename = "logfile.txt";   
  2.   
  3.  strcpy(fullpath, "c:\\tmp");   
  4.   
  5.  lr_output_message ("fullpath after strcpy: %s", fullpath);   
  6.   
  7.  strcat(fullpath, "\\");   
  8.   
  9.  strcat(fullpath, filename);   
  10.   
  11.  lr_output_message ("Full path of file is %s", fullpath);}   
  12.   
  13. Output:  
  14. Action.c(6): fullpath after strcpy: c:\tmp  
  15. Action.c(10): Full path of file is c:\tmp\logfile.txt   

函数名:strlen

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

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

[csharp]  view plain  copy
  1.  int is_digit, i = 0;   
  2.   
  3.  char * str = "1234567k89";   
  4.   
  5.  unsigned int len = strlen(str);   
  6.   
  7.  do {   
  8.   
  9.      if (i == len) {   
  10.   
  11.          lr_output_message ("No letters found in string");   
  12.   
  13.          return -1;   
  14.   
  15.      }   
  16.   
  17.      is_digit = isdigit(str[i++]);   
  18.   
  19.  } while (is_digit);   
  20.   
  21.  lr_output_message ("The first letter appears in character %d of string", i);}   
  22.   
  23. Output:  
  24. Action.c(18): The first letter appears in character 8 of string<strong>  
  25. </strong>  
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值