c - 预期 ';' 标识符或 '(' 之前的 'void' token ?

标签 c debugging

<分区>

我正在尝试编译我的代码,但我得到了预期的 ';' 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 0;

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

int nu,i;              //global vars

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

编辑: 后两条注释显然不会导致编译错误,但我认为无论如何提及它们都是一个好主意。

关于c - 预期 ';' 标识符或 '(' 之前的 'void' token ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41129576/

相关文章:

c - C 结构中的默认值

c - 解析 C 头文件以确定所有定义的宏

java - dumpstack() 和 printStackTrace() 之间的区别

visual-studio - 在 Visual Studio 2012/2013 中自动 "Attach to Running Process"

maven - Intellij + springboot + maven + spring加载

c - Futoshiki C 递归求解器

c++ - 如何在 C++ 中确定 2D 无符号短指针数组长度

c - C 和汇编器中的阶乘 - 递归

c++ - 在 Visual Studio 调试器中,{null=???} 是什么意思?

java - Eclipse java调试: source not found