📄 errors1.txt
字号:
*The debugging of the wordlist.cpp*
1.
The first error was hidden in this piece of word:
"delete word_list;".
word_list was dynamicly distributed with more than one block of memory space. So that when we intend to delete it, we should delete them all with the sentence like that:
"delete[] word_list;".
Or there would hide an unknown dubious trouble.
===========================================================
2.
After I fixed that sentence, I move to the next, and found that the new_word_list was just a string.
"string new_word_list = *(new string[2 * capacity])"
It couldn't hold all of the word_list's value but the only value in the last loop. Data loss happened in that way. So I modified the sentence. The result is that:
"string* new_word_list = new string[2 * capacity];"
Now new_word_list had the ability to hold the value of word_list. To make it hold the data indeedly, we need to modify the sentence:
"new_word_list = word_list[index];"
to:
"new_word_list[index] = word_list[index];"
===========================================================
3.
Redistribution for the word_list was needed after its value was stored. But the sentence:
"*word_list = new_word_list;"
was incorrect. I rewrited it to :
"word_list = new string[2*capacity]"
And the loop was also rewrited, shown below:
"for (index = 0; (index < capacity); index++) {
word_list[index] = new_word_list[index];
}"
===========================================================
4.
Now the function build_wordlist was without bug. But one essential problem was still remained. That was word_list can not get the new space distributed in the function, if the string information is larger than the capacity. To solve that problem, I choice to change the function's return type.
"void build_wordlist"
to :
"string* build_wordlist"
And one sentence was added to the rear of the function.
"return word_list;"
Also, one modification in the main function:
"word_list = build_wordlist"
===========================================================
Till now, the program can run successfully.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -