spellcheck.cpp
来自「这是一本数据结构C++算法的完整的源代码」· C++ 代码 · 共 64 行
CPP
64 行
#include <iostream>#include <fstream>#include <cstdlib>#include <cstring>#include <cctype>using namespace std;#include "trie.h"char* strupr(char *s) { char *ss; for (ss = s; *s = toupper(*s); s++); return ss;}int main(int argc, char* argv[]) { char fileName[25], s[80], ch; int i, lineNum = 1; ifstream dictionary("dictionary"); if (dictionary.fail()) { cerr << "Cannot open 'dictionary'\n"; exit(-1); } dictionary >> s; Trie trie(strupr(s)); // initialize root; while (dictionary >> s) // initialize trie; trie.insert(strupr(s)); trie.printTrie(); if (argc != 2) { cout << "Enter a file name: "; cin >> fileName; } else strcpy(fileName,argv[1]); ifstream textFile(fileName); if (textFile.fail()) { cout << "Cannot open " << fileName << endl; exit(-1); } cout << "Misspelled words:\n"; textFile.get(ch); while (!textFile.eof()) { while (true) if (!textFile.eof() && !isalpha(ch)) { // skip non-letters if (ch == '\n') lineNum++; textFile.get(ch); } else break; if (textFile.eof()) // spaces at the end of textFile; break; for (i = 0; !textFile.eof() && isalpha(ch); i++) { s[i] = toupper(ch); textFile.get(ch); } s[i] = '\0'; if (!trie.wordFound(s)) cout << s << " on line " << lineNum << endl; } dictionary.close(); textFile.close(); return 0;}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?