Closed. This question is off-topic. It is not currently accepting answers. Learn more
想改进这个问题吗?Update the question所以堆栈溢出的值小于aa>。
两年前关闭。
我正在试图编译我的代码,并在C:10:1上获得预期的“;”标识符或“(”void“错误之前的标记。。如果有人能帮我,我会很感激的!我已经在下面提供了我的代码,我确信这只是我在某个地方犯的一个愚蠢的错误。
#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;
       }
   }

最佳答案

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

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

而且,你的main()函数应该return一些东西。在结尾处加上return 0;
还有一件事我注意到了。在这里:
int nu,i;              //global vars

注释没有任何意义,因为nui不是全局变量。它们是局部变量,因为它们是在main()函数的作用域中声明的。
编辑:
后两条评论显然没有导致编译错误,但我认为无论如何提到它们都是一个好主意。

08-05 10:20
查看更多