(43 ~ 56 행) pset 5에 대한로드 기능을 구현하려고합니다. 중첩 된 while 루프를 만들었습니다. 처음에는 파일 끝까지 반복하고 각 단어의 끝까지 다른. 나는 사전에서 검색대로 "문자열"저장 숯불 *의 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]
}
지금 잠시 동안 함께 놀았 던, 그리고 실망입니다. 도와주세요. 추가 버그를 발견하면 기쁠 것입니다.
' '/ 0'' ---->''\ 0'' – rsp
@rsp 아니면 그냥 0, 따옴표없이, 혼동이 아닙니다. – cnicutar
또는''??/0'' ('\'가없는 경우). –