# LR中常用的C函数

63 篇文章 14 订阅

1，将字符串中的数字转换为浮点数的函数，如果不事先声明，则转换有问题。
1       strcat

char *strcat ( char *to, const char *from );

 char test[1024], *a = "slo@hotmail.com";        strcpy(test, "zee");        strcat(test, a);        lr_output_message("We can see %s",test);

 Starting action Action. Action.c(16): We can see zeeslo@hotmail.com

2       strchr
char * strchr ( const char * string, int c );

 char *string = "Zee is a tester";      char *first_e, *last_e;        first_e = (char *)strchr(string, 'e');      lr_output_message("We can see the first occurrence of e: %s",first_e);      last_e = (char *)strrchr(string, 'e');      lr_output_message("We can see the last occurrence of e: %s", last_e);

 Starting action Action. Action.c(12): We can see the first occurrence of e: ee is a tester Action.c(14): We can see the last occurrence of e: er

3       Strcmp＆stricmp
int strcmp ( constchar * string1, const char * string2 );大小写敏感。
int stricmp ( const char * string1, const char * string2 );大小写不敏感。

 int result;      char tmp[20];      char string1[] = "We can see the string:ZEE";      char string2[] = "We can see the string:zee";        result = strcmp( string1, string2 ); /*区分大小写，比较字符串 */        if( result > 0 )           strcpy( tmp, "大于" );      else if( result < 0 )           strcpy( tmp, "小于" );      else           strcpy( tmp, "等于" );        lr_output_message( "strcmp: String 1 %s string 2", tmp );        result = stricmp( string1, string2 ); /* 不区分大小写，比较字符串 */        if( result > 0 )           strcpy( tmp, "大于" );      else if( result < 0 )           strcpy( tmp, "小于" );      else           strcpy( tmp, "等于" );        lr_output_message( "stricmp: String 1 %s string 2", tmp );

 Starting action Action. Action.c(22): strcmp: String 1 小于 string 2 Action.c(33): stricmp: String 1 等于 string 2

4       strcpy
char * strcpy ( char * dest, const char * source );

 char test[1024];        strcpy(test, "what can we see?       ");        lr_output_message("%s", test);

 Starting action Action. Action.c(10): what can we see?

5       Strdup& strlwr
char * strdup ( const char * string );

char * strlwr ( char * string );

 int id;      char *groupname_static, *groupname;        /* 从VuGen中得到组名 */      lr_whoami(&id, &groupname_static, NULL);      lr_output_message("groupname=%s", groupname_static);        /*复制这个静态组名以便我们可以操作它 */      groupname = (char *)strdup(groupname_static);      groupname = (char *)strlwr(groupname);      lr_output_message("lower case groupname=%s", groupname);        free(groupname);

 Starting action Action.     [MsgId: MMSG-15919] Action.c(11): groupname=CHANGE      [MsgId: MMSG-17999] Action.c(16): lower case groupname=change       [MsgId: MMSG-17999]

6       Strlen
size_t strlen ( constchar * string );

 char *str = "Zee is a tester";      unsigned int len;        len = strlen(str);        lr_output_message("The sentence has %d letters",len);

 Action.c(13): The sentence has 15 letters

7       Strncat
char * strncat ( char * to_ string, const char * from_string, size_t n );

 char str1[]="Zee is ";     char str2[]="a tester.";     lr_output_message("What can we see?");     lr_output_message("The str1 is %s.",str1);       strncat(str1,str2,20); lr_output_message("The str1 is %s.",str1);

 Action.c(9): What can we see? Action.c(10): The str1 is Zee is . Action.c(13): The str1 is Zee is a tester..

8       strncmp
int strncmp ( constchar * string1, const char * string2, size_t n );

 char result;     char str1[]="Zee is a tester.";     char str2[]="Zee is a tester.";     char str3[]="zee is a tester?";         result = strcmp(str1,str2);       if(result > 0)          lr_output_message("str1 is greater than str2.");     else if(result < 0)          lr_output_message("str1 is less than str2.");     else          lr_output_message("str1 is equal to str2.");        result = strncmp( str1, str3 , 30);         if(result > 0)          lr_output_message("str1 is greater than str3.");     else if(result < 0)          lr_output_message("str1 is less than str3.");     else          lr_output_message("str1 is equal to str3.");

 Starting iteration 1. Starting action Action. Action.c(18): str1 is equal to str2. Action.c(28): str1 is less than str3.

• 0
点赞
• 1
收藏
觉得还不错? 一键收藏
• 打赏
• 6
评论
08-21 1087
03-25 133
06-30 107
08-20
10-07

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

• 非常没帮助
• 没帮助
• 一般
• 有帮助
• 非常有帮助

7DGroup

¥2 ¥4 ¥6 ¥10 ¥20

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