预期的 ';'标识符或'('在'void'之前的标记? [英] Expected ';' identifier or '(' token before 'void'?

查看:59
本文介绍了预期的 ';'标识符或'('在'void'之前的标记?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编译我的代码,并且得到了期望的';'C:10:1 ..中'void'错误前的标识符或'('令牌)如果有人可以帮助我,我似乎找不到错字,我将不胜感激!我提供了下面的代码,我确定是只是我在某个地方犯的一个愚蠢的错误.

I am trying to compile my code and I am getting the Expected ';' identifier or '(' token before 'void' error on C:10:1.. can't seem to find the typo if someone can help me out I would appreciate it! I have provided my code down below I am sure it is just a silly mistake I made somewhere.

#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;
       }
   }

推荐答案

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

You need to add semicolon (;) after declaration of your struct:

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

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

Also, your main() function should return something. Add return 0; at the end of it.

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

And one more thing I noticed. Here:

int nu,i;              //global vars

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

The comment does not make any sense, as nu and i are not global variables. They are local variables, because they are declared in the scope of your main() function.

后两个注释显然不会引起编译错误,但是我认为还是要提及它们是一个好主意.

The latter two comments obviously did not cause the compiling error, but I thought it would be a good think to mention them anyway.

这篇关于预期的 ';'标识符或'('在'void'之前的标记?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆