#include #include #include #include using namespace std; struct Word{ string key; string meaning[500]; }; typedef struct node{ Word info; node *next; }; typedef struct list{ node *head; node *tail; }; void clearString( string a[500]) { for (int i = 0; i < 500;i++) { a[i] = " "; } } node* getNode(Word w) { node *p; p = new node; if (p == NULL) { cout << "Khong du bo nho"; exit(1); } p->info.key = w.key; for (int i = 0; i < 500; i++) { p->info.meaning[i] = w.meaning[i]; } p->next = NULL; return p; } void insertTail(list &l, Word w) { node *p = getNode(w); if (p == NULL) { cout << "Khong tao duoc nut moi"; exit(1); } if (l.head == NULL) { l.head = l.tail = p; } else{ l.tail->next = p; l.tail = p; } } void printList(list l) { node *p; p = l.head; while (p != NULL) { cout << "=============================================" << endl; cout << p->info.key<info.meaning[i] == "") continue; cout << p->info.meaning[i]<next; } } void cleanArray(string a[500]) { for (int i = 0; i < 500; i++) { a[i] = ""; } } const int limit = 600000; void readFileToList(char *fileName, list &l){ FILE *f; Word w; node *p = NULL; int z = 0; f = fopen(fileName, "rt"); if (f == NULL) { cout << " khong tim thay file!"; return; } while( !feof(f)) { char s[255]; fgets(s, 255, f); if (s[0] == '@') { char tuKhoa[255]; int j; j = 1; while (j < strlen(s) && s[j] != '/') { tuKhoa[j - 1] = s[j]; j++; } tuKhoa[j - 2] = NULL; w.key = (string)tuKhoa; } else { if (s[0] != '\n') { w.meaning[z] = s; z++; } else { insertTail(l, w); cleanArray(w.meaning); z = 0; } } } fclose(f); } void main() { list l; char *FileName = new char[255]; l.head = l.tail = NULL; strcpy(FileName, "anhviet109_KoDau.txt"); readFileToList(FileName,l); //printList(l); cout << "D O N E !" << endl; _getch(); }