-
LR_strdup
2007-09-04 09:21:19
-
LR_strcmp and LR_stricmp
2007-09-04 09:03:37
一、strcmp
Compares string1 and string2 to determine the alphabetic order.
int strcmp ( const char *string1, const char *string2 ); //注意是int
strcmp compares string1 and string2 to determine the alphabetic order.
返回值:
Returns a value indicating the lexicographical relation between the strings:
Return valueDescrīption<0string1 is less than string20string1 is the same as string2>0string1 is greater than string2二、stricmp(与strcmp的区别仅为忽略大小写)Performs a case-insensitive comparison of two strings.
int stricmp ( const char *string1, const char *string2 );
stricmp performs a case-insensitive comparison of two strings.
Returns a value indicating the lexicographical relation between the strings:
脚本说明:
The following example compares two strings, string1 and string2, which are identical except for the word "quick" which is lowercase in string1 and uppercase in string2. strcmp, which is case-sensitive, returns an unequal comparison. stricmp, which ignores case, returns an equal one.
下面的例子比较了两个字符串,string1和string2,除了单词"quick"在string1中为小写字母,在string2中为大写字母外,其他字母都是相同的。strcmp,是大小写敏感的,这个函数会返回一个不相同的结果。stricmp,会忽略大小写,返回相同的结果
#include "web_api.h"
Action() {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 );
return 0;
}结果:
Action.c(20): strcmp: String 1 is greater than string 2
Action.c(31): stricmp: String 1 is equal to string 2 -
LR_strchr and LR_strrchr
2007-09-04 08:39:48
一、strchr
char *strchr ( const char *string, int c );
stringThe string that is searched.在哪个字符串进行寻找?cThe character that is searched for in the string.寻找哪个字符?strchr returns the pointer to the first occurrence of a character in a string.
strchr指向第一次出现寻找到的字符的位置
二、strrchr
(与strchr相对应的最后一个字符串)
char *strrchr ( const char *string, int c );
strrchr finds the last occurrence of a character in a string.
#include "web_api.h"
Action() {char *string = "His Excellency txhe Duke of Exeter";
char *first_x, *last_x;first_x = (char *)strchr(string, 'x');
lr_output_message("The first occurrence of x: %s", first_x);
last_x = (char *)strrchr(string, 'x');
lr_output_message("The last occurrence of x: %s", last_x);return 0;
}/*
这个函数的意义是:strchr:找出从字符串开始的第一个x字符,并把
这个x和x后面的字符全部显示出来
那么strrchr就是找到从给定字符串开始最后一个x字符,并把
最后这个x和它后面的字符全部显示出来
运行结果:
Action.c(11): The first occurrence of x: xcellency txhe Duke of Exeter
Action.c(13): The last occurrence of x: xeter
*/ -
LR_strcat and LR_strcpy
2007-09-03 16:24:50
一、strcat
Concatenates two strings.
char *strcat ( char *to, const char *from );
toThe string at the end of which the from string is concatenated.fromThe string concatenated to the end of the to string.strcat concatenates two strings.
二、strcpy
Copies one string to another.
char *strcpy ( char *dest, const char *source );
strcpy copies one string to another.
注意:
注意将字符串或者字符串常量放在一个字符变量中,而且字符变量需要设置长度,如果不设置会出错。如下:Action.c(16): Error: C interpreter run time error: Action.c (16): Error -- memory violation : Exception ACCESS_VIOLATION received.
Action.c(16): Notify: CCI trace: Action.c(16): strcat(0, 0x00e3023e "aaa")
.
Action.c(16): Notify: CCI trace: Compiled_code(0): Action()
.Action(){char *a="aaa";
char *b="bbb";
char c[1024];
char fullpath[1024], *filename = "logfile.txt";strcpy(fullpath, "把它考到fullpath中");
strcat(fullpath, "【这个字符连接到fullpath后面】");
strcat(fullpath, filename);lr_output_message("Full path of file is %s", fullpath);
strcat(c,a);
strcat(c,b);
strcat(c,a);
lr_output_message("%s",a);
lr_output_message("%s",b);
lr_output_message("%s",c);
return 0;
} -
将参数化内容输出到.txt文件中
2007-07-22 00:25:49
将参数化内容输出到文件中
文件位置:C:\jiris.txt
输出方式为追加输入。~
其实没有什么意义~~只是学一下写文件~
char *filename = "c:\\jiris.txt";
Action() {long file;
if ((file = fopen(filename, "a" )) == NULL) {lr_output_message("Unable to create %s", filename);
return -1;
}
fprintf(file, "%s",lr_eval_string("{number}"));
lr_output_message("%s",lr_eval_string("{number}"));
fprintf(file,"\n");
fclose(file);return 0;
}
-
1. fopen【翻】
2007-07-21 16:31:33
my english level is listed~~~~大概意思,如果有错误,欢迎指出~~----------Opens a file for buffered I/0.打开文件到IO缓冲器FILE *fopen ( const char *filename, const char *access_mode );The access_mode parameter serves also to specify whether we want to open the file as text or binary, adding t or b characters to this access mode string.
存取方式参数也可以制定我们要打开的文件类型,是.txt还是二进制格式,用t或者b表示
Do not include operating system header files (e.g. stdio.h) in scrīpts. This will result, however, in some types, including the FILE type used here, to be undefined. Instead, substitute a long for the FILE type.
不要在脚本中定义头文件,如stdio.h。如果包含了FILE类型在这里使用的话,可能会有这样的结果,就是FILE未定义。此时,可以用long声明FILE~