如何在c中的main函数中声明struct变量?

时间:2014-03-19 10:47:15

标签: c parameter-passing

我是c编程的新手,我的代码正在运行,但我的问题是,如果我在main函数中声明struct node *a,*b;,如何将ab传递给{{1}并且为什么它不起作用,有人可以帮我理解吗?

void create()

2 个答案:

答案 0 :(得分:0)

void main()
{
  struct node name_of_varialbe;//this is struct variable declaration
  ...
}    

答案 1 :(得分:0)

只需将void create()的原型更改为void create(struct node *,struct node *),然后按以下方式调用:

char ch;

do
{
    struct node *a_main=(struct node *)malloc(sizeof(struct node));
    struct node *b_main=(struct node *)malloc(sizeof(struct node));
    create(a_main,b_main);   
    printf("Do you want to create another : ");
    ch=getche();
}while(ch!='n');

void create(struct node *a,struct node *b)
{
    //do your stuff
}