预期';'标识符或'('''之前的'令牌?

时间:2016-12-13 20:00:37

标签: c debugging

我正在尝试编译我的代码,我得到了预期的';'标识符或'('''''''''''''''''''''''''''''''''''''''''''... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...我在某处犯了一个愚蠢的错误。

#include <stdio.h>
#include <stdlib.h>

//setting up my binary converter struct
struct bin
{
    int data;
    struct bin *link;
}
void append(struct bin **, int);        //setting up append value
void reverse(struct bin**);         //reverse values to convert to binary
void display(struct bin *);         //so we can display

int main(void)
{
     int nu,i;              //global vars
     struct bin *p; 

     p = NULL;              //setting up p pointer to NULL to make sure it has no sense of being some other value

     printf("Enter Value: ");
     scanf("%d", &nu);

     while (nu != 0)
     {
        i = nu % 2;
        append (&p, i);
         nu /= 2;
     }

     reverse(&p);
     printf("Value in Binary: ");
     display(p);
}
  //setting up our append function now
void append(struct bin **q, int nu)
{   
     struct bin *temp,*r;
     temp = *q;

     if(*q == NULL)                             //making sure q pointer is null
     {   
          temp = (struct bin *)malloc(sizeof(struct bin));
          temp -> data = nu;
          temp -> link = NULL;
          *q = temp;
     }
     else
     {
          temp = *q;
          while (temp -> link != NULL)
          {
              temp = temp -> link;
          }
          r = (struct bin *) malloc(sizeof(struct bin));
          r -> data = nu;
          r -> link = NULL;
          temp -> link = r;
    }
    //setting up our reverse function to show in binary values
   void reverse(struct bin **x)
   {
        struct bin *q, *r, *s;
        q = *x;
        r = NULL;

       while (q != NULL)
       {
           s = r;
           r = q;
           q = q -> link;
           r -> link = s;
       }
       *x = r;
   }
   //setting up our display function
   void display(struct bin *q)
   {
       while (q != NULL)
       {
             printf("%d", q -> data);
             q = q -> link;
       }
   }

1 个答案:

答案 0 :(得分:1)

您需要在声明结构后添加分号(;):

struct bin
{
  int data;
  struct bin *link;
};

此外,您的main()函数应return。在其末尾添加return 0;

还有一件事我注意到了。这里:

int nu,i;              //global vars

评论没有任何意义,因为nui不是全局变量。它们是局部变量,因为它们是在main()函数的范围内声明的。

编辑: 后两条评论显然没有引起编译错误,但我认为无论如何都要提及它们是个好主意。