当前位置: 技术问答>linux和unix
字符指针数组参数传递问题?
来源: 互联网 发布时间:2016-07-10
本文导语: 代码如下: ........ ........ ........ char** ossm_rule(struct ossm_rule_node * rule,char * *ruleset) { char *p = (char *)malloc(100); memset(p,0,100); int i = 0; struct ossm_rule_node *node = rule; while(node != NULL) { strcpy(p,"lids...
代码如下:
........
........
........
char** ossm_rule(struct ossm_rule_node * rule,char * *ruleset)
{
char *p = (char *)malloc(100);
memset(p,0,100);
int i = 0;
struct ossm_rule_node *node = rule;
while(node != NULL)
{
strcpy(p,"lidsconf -");
strcat(p,node -> action);
strcat(p," ");
if(node -> state)
strcat(p,node -> state);
strcat(p," ");
if(node -> subject)
{
strcat(p,"-s ");
strcat(p,node -> subject);
strcat(p," ");
}
strcat(p,"-o ");
strcat(p,node -> object);
strcat(p," ");
strcat(p,"-j ");
strcat(p,node -> privilege);
ruleset[i++] = p;
printf("%sn",ruleset[i-1]);//此处能够正确输出字符串
memset(p,0,100);
printf("%dn",i);
node = node -> next;
}
free(p);
p = NULL;
return ruleset;
}
int main()
{
int k;
char *file = "rule_to_set.xml";
struct ossm_rule_node *rnode = proc_xml_parse(file);
char *rule_set[50];
for(k = 0;k
........
........
........
char** ossm_rule(struct ossm_rule_node * rule,char * *ruleset)
{
char *p = (char *)malloc(100);
memset(p,0,100);
int i = 0;
struct ossm_rule_node *node = rule;
while(node != NULL)
{
strcpy(p,"lidsconf -");
strcat(p,node -> action);
strcat(p," ");
if(node -> state)
strcat(p,node -> state);
strcat(p," ");
if(node -> subject)
{
strcat(p,"-s ");
strcat(p,node -> subject);
strcat(p," ");
}
strcat(p,"-o ");
strcat(p,node -> object);
strcat(p," ");
strcat(p,"-j ");
strcat(p,node -> privilege);
ruleset[i++] = p;
printf("%sn",ruleset[i-1]);//此处能够正确输出字符串
memset(p,0,100);
printf("%dn",i);
node = node -> next;
}
free(p);
p = NULL;
return ruleset;
}
int main()
{
int k;
char *file = "rule_to_set.xml";
struct ossm_rule_node *rnode = proc_xml_parse(file);
char *rule_set[50];
for(k = 0;k