请教
目的:生成一个随机字符串dialogid,在后面脚本中要用到这个参数Action()
{
int l;
int i;
char *id;
id = "dlg"+randomChar(12);
randomChar(l)
{
char *x;
char *tmp;
int j;
x = "1234567890qwertyuioplkjhgfdsazxcvbnm";
tmp = "";
for (i = 0; i < l; i++)
{
j =(rand(2) * 100000000) % strlen(x);
tmp+ = j;
}
return tmp;
}
lr_save_string(id,"dialogid");
}
编译老是通不过,请哪位高手帮忙指点下
编译信息如下:
Action.c (8): syntax error; found `{' expecting `;'
Action.c (17): illegal character `\0243'
Action.c (17): illegal character `\0250'
Action.c (17): syntax error; found `)' expecting `;'
Action.c (17): illegal statement termination
Action.c (17): skipping `)' `%'
Action.c (18): illegal expression
Action.c (18): syntax error; found `strcat' expecting `;'
Action.c (20): illegal return type; found `pointer to char' expected `int'
Action.c (22): warning: unreachable code
e:\\work \324\332 172.17.118.223 \311\317\\\320\255\315\254oa\\g1\\\\combined_g1.c (5): 9 errors, not writing pre_cci.ci
[ 本帖最后由 guoxianchina 于 2010-8-12 16:56 编辑 ] 首先
randomChar(l)
改成(加分号)
randomChar(l);
然后
tmp+ = j;
改成(+和=是一伙的)
tmp += j;
最后
return tmp;
改成(tmp是指针,如果你要返回指针指向的内容的话,应该加星号)
return *tmp;
这只能保证编译通过,运行似乎还有些小问题 这个脚本错误之多真是让我汗颜,先说个简单问题,action()的圆括号写成全角了,所以错了,后面各种取值都是错的。。。
特别是你取随机字符,怎么能用strlen()函数呢。。 今天心情好专门写了个randomchar的函数给你,记得留版权哦。。。
//create by cloudchen 2010.8.12 in beijing
//randomchar 调用该函数输入一个int型字符串长度和一个参数名,会自动生成由a-z,A-Z,0-9的随机字符串并用该参数名返回
void RandomChar(int mystrlen,char *paramname)
{
char tmp;
int i;
strcpy(tmp,"Cloud");//这里自己可以定义需要生成字符串的开头
for (i = 0; i<mystrlen; i++)
{
lr_save_var("abcdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ"+(rand()%61+1),1,0,"temp");
strcat(tmp,lr_eval_string("{temp}"));
//lr_output_message(tmp);
}
lr_save_string(tmp,paramname);
}
Action()
{
RandomChar(12,"mystr");
lr_output_message("this is my needs random string=%s",lr_eval_string("{mystr}"));
return 0;
} <自己改成小于号"<",论坛会过滤转义 哇,真是感谢各位,特别是云层老师 真好,很符合我想要的东东
页:
[1]