2017-09-05 16 views
0

(43〜56行目)pset 5のロード関数を実装しようとしています。入れ子のwhileループを作成しました。他の単語の終わりまで。私は辞書からスキャンどんな「文字列」を格納するためのchar * cを作成したが、私は、コンパイル時に複数文字の定数[-Werror、-Wmultichar]

bool load(const char *dictionary) 
{ 
    //create a trie data type 
    typedef struct node 
    { 
     bool is_word; 
     struct node *children[27]; //this is a pointer too! 
    }node; 

    FILE *dptr = fopen(dictionary, "r"); 
    if(dptr == NULL) 
    { 
     printf("Could not open dictionary\n"); 
     unload(); 
     return false; 
    } 

    //create a pointer to the root of the trie and never move this (use traversal *) 
    node *root = malloc(sizeof(node)); 
    char *c = NULL; 

    //scan the file char by char until end and store it in c 
    while(fscanf(dptr,"%s",c) != EOF) 
    { 
     //in the beginning of every word, make a traversal pointer copy of root so we can always refer back to root 
     node *trav = root; 

     //repeat for every word 
     while ((*c) != '/0') 
     { 
     //convert char into array index 
     int alpha = ((*c) - 97); 

     //if array element is pointing to NULL, i.e. it hasn't been open yet, 
     if(trav -> children[alpha] == NULL) 
      { 
      //then create a new node and point it with the previous pointer. 
      node *next_node = malloc(sizeof(node)); 
      trav -> children[alpha] = next_node; 

      //quit if malloc returns null 
      if(next_node == NULL) 
       { 
        printf("Could not open dictionary"); 
        unload(); 
        return false; 
       } 

      } 

     else if (trav -> children[alpha] != NULL) 
      { 
      //if an already existing path, just go to it 
      trav = trav -> children[alpha]; 
      } 
     } 
     //a word is loaded. 
     trav -> is_word = true; 

    } 
} 

エラー:

dictionary.c:52:23: error: multi-character character constant [- 
     Werror,-Wmultichar] 
     while ((*c) != '/0') 

私は、これは'/0'は単一の文字でなければなりません意味だと思いますが、私ドン私はその言葉の終わりをどうやって確認するのか分からない! 私も言って、別のエラーメッセージが表示されます。

dictionary.c:84:1: error: control may reach end of non-void function [-Werror,-Wreturn-type] 
    } 

私は今しばらくそれでプレーしてきた、そしてそれはイライラさせられます。助けてください。追加のバグが見つかったら、私はうれしく思います!

+3

''/ 0'' ---->'' \ 0'' – rsp

+1

@rspまたは0、引用符なし、混乱はありません。 – cnicutar

+0

'' ??/0 ''(あなたに' \ 'がない場合)。 –

答えて

0

'/ 0'の代わりに '\ 0'(ヌル終了文字)を使用します。 また、関数の最後にboolを返すことを忘れないでください!

+0

ありがとう!どういう間違いですか – jasson

+0

@jason Lim:どうぞよろしく! – cydef

関連する問題