struct element string value element next void __fastcall TForm3 BitBtn

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
struct element
{
string value;
element* next;
};
void __fastcall TForm3::BitBtn1Click(TObject *Sender)
{
element *pointer, head;
string s;
char c;
pointer=&head;
FILE *f=fopen(FileListBox1->FileName.c_str(),"r");
while (fgetc(f)!=EOF)
{ c=fgetc(f);
if (c=='\n')
{
pointer->next = new element;
pointer=pointer->next;
pointer->value = s;
pointer->next=NULL;
s.clear();
}
else s+=c;
}
char word[100];
vector <string> v;
string w, str;
pointer=&head;
pointer=pointer->next;
while ( pointer!=NULL)
{
sscanf(pointer->value.c_str(),"[\w+]", &word);
w = word;
if (find(v.begin(),v.end(),w)==v.end())
v.push_back(w);
pointer=pointer->next;
}
sort(v.begin(), v.end());
for(int i=0;i<v.size();i++)
str+=v[i]+",";
ShowMessage(str.c_str());
}