2016-12-13 49 views
1

我試圖編譯我的代碼,我得到預期的「;」標識或「(」令牌之前,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; 
     } 
    } 
+3

缺少',''後結構斌{...}' – EOF

回答

1

您需要添加分號(

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

此外,您main()函數應該return SOMET:;)你的結構的聲明後,興。在末尾添加return 0;

還有一兩件事我注意到了。在這裏:

int nu,i;    //global vars 

的意見沒有任何意義,因爲nui不是全局變量。它們是局部變量,因爲它們在您的main()函數的範圍內聲明。

編輯: 後兩個意見顯然沒有導致編譯錯誤,但我認爲這是一個很好的想法,無論如何提及它們。

+0

編譯器插入一個隱含的'返回0;對於''main'。但是''''是個好地方。 – Bathsheba

+0

當然失蹤'return'它沒有造成問題,但我認爲這是給它這麼寫一個好主意。 –

+1

但這條教條毀了一個很好的答案。 – Bathsheba

相關問題