2017-09-02 42 views
1

我有一個main功能作爲一個更大的項目,是作爲其一部分的兩個或更多的數據類型如下:錯誤:在主聲明符()

#include <stdio.h> 
#include <stdlib.h> 
#include <string.h> 
#include "header2.h" 

int 
main(int argc, char *argv[]) { 
    node_t *tst=NULL; 
    int weight; 
    char prefix[CHARMAX]; 
    FILE *datafile = fopen(argv[1],"r"); 
    while (fscanf(datafile,"%d;%[^\n]", &weight, prefix)==2) { 
    tst=insert(tst,prefix,weight); 
    } 
    fclose(datafile); 
    while (fscanf(stdin,"%s",prefix)) { 
    printf("Prefix: %s ",prefix); 
    FILE *out = fopen(argv[2],"a"); 
    fprintf(out,"Prefix: %s\n",prefix); 
    fclose(out); 
    find_and_traverse(tst,(char*)prefix); 
    } 
    return 0; 
} 

我編譯我的生成文件的一部分,並得到這個錯誤:

stage2.c:2:1: error: two or more data types in declaration specifiers 
int main(int argc, char *argv[]) { 
^ 

線2包括<stdlib.h>,所以我真的不知道是什麼原因造成這個錯誤。

關於header2.h內容 - 考慮到誤差指着2號線不就行了4我不認爲這是必要的 - 但在這裏它是:

typedef struct node { 
    char data; 
    unsigned end_of_string: TRUE; 
    struct node *left; 
    struct node *equal; 
    struct node *right; 
    int weight; 
} node_t; 

typedef struct sorted_node { 
    char data[250]; 
    int weight; 
} sorted_node_t; 

node_t* insert(node_t* pNode, char* word, int weight); 
void find_and_traverse(node_t* pNode, char* prefix); 
void selectionsort(node_t* pNode, char* buffer, int depth, int max); 
void sort(sorted_node_t arr[], int n); 

請幫幫忙!

+0

所以你明白'header2.h'的內容可以引起這個,但是不要在你的問題中包含它們。當然你可以看到這個問題有多難以回答? – hvd

+0

@hvd添加了header2.h文件。由於錯誤指向第2行而不是4,我認爲這不是必需的 – vulcanoiding

+1

我不確定''unsigned end_of_string:TRUE;''typedef''是否正確。請刪除':TRUE'並重試。 –

回答

0

我最初的猜測是在頭文件header2.h的末尾有一個缺失的;,但看着header2.h的內容,它似乎不是問題所在。

什麼是最令人驚訝的是錯誤消息:

stage2.c:2:1: error: two or more data types in declaration specifiers 
int main(int argc, char *argv[]) { 
  • 線2沒有此內容(如你注意到)
  • 在片段中的main定義發佈拆分2線,但在錯誤消息中顯示爲一行。您是否可以將源文件中的定義修改爲int main(int argc, char **argv) {以驗證錯誤消息是否更改,並確實與您認爲它的文件有關?也

注意typedef內的聲明unsigned end_of_string: TRUE;定義1位寬度的位字段end_of_string