预期';'标识符或“(”令牌之前“无效”
问题描述:
我试图编译我的代码,我得到预期的“;”标识或“(”令牌之前,C“无效”的错误:?10:1 ..可以”不像是会找错字,如果有人能帮助我我将不胜感激!我提供我的代码楼下,我相信这只是一个愚蠢的错误,我什么地方做。预期';'标识符或“(”令牌之前“无效”
#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
SOMET:;
)你的结构的声明后,兴。在末尾添加return 0;
。
还有一两件事我注意到了。在这里:
int nu,i; //global vars
的意见没有任何意义,因为nu
和i
不是全局变量。它们是局部变量,因为它们在您的main()
函数的范围内声明。
编辑: 后两个意见显然没有导致编译错误,但我认为这是一个很好的想法,无论如何提及它们。
缺少',''后结构斌{...}' – EOF