您的位置:首页 > 编程语言 > C语言/C++

LoadRunner中常用的C语言函数

2015-09-18 14:14 483 查看

函数名: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( constchar *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

返回值描述
<0string1 小于string2
0string1 等于string2
>0string1 大于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( constchar *string
);

[align=left][/align]

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>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: