|
我为了测试一下Windows和Linux下的C编译文件的大小,在Windows里写了一个C++的小程序,在VC6下编译通过,运行也正常,但换到Linux下无论是用gcc还是g++编译都不过,说是让我使用32位的库
把代码粘一下,哪位给看看
- //count.cpp
- #include <iostream.h>
- #include <fstream.h>
- char PubWord[255];
- class myWord
- {
- public:
- myWord(){setNull();};
- myWord(char Letter) {setNull(); myLetter = Letter;};
- ~myWord(){for (int i=0; i<26; i++) {if (!Next[i]) {delete Next[i];}}};
- void setNull(){myCount =0; for (int i=0; i<26; i++) {Next[i] = 0;}};
- char myLetter;
- int myCount;
- myWord *(Next[26]);
- };
- int ReadWord(ifstream File, char * Word)
- {
- char * r = new(char);
- do{
- File.read(r, 1);
- if ((*r>='A') && (*r<='Z'))
- {
- *r += 'a' - 'A';
- }
- if (File.eof()) return 0;
- }while(!(((*r>='a') && (*r<='z')) || (*r==0) || File.eof()));
- if (*r)
- {
- while (*(Word++) = *r)
- {
- if (File.eof()) break;
- File.read(r, 1);
- if ((*r>='A') && (*r<='Z'))
- {
- *r += 'a' - 'A';
- }
- if ((*r>'z') || (*r<'a')) break;
- }
- *Word = 0;
- return 1;
- }
- else
- {
- return 0;
- }
- }
- void CountWord(myWord * Root, char * Word)
- {
- if (*(++Word))
- {
- char r = *Word;
- if (!(Root->Next[r-'a']))
- {
- Root->Next[r-'a'] = new myWord(r);
- }
- CountWord(Root->Next[r-'a'], Word);
- }
- else
- {
- Root->myCount++;
- }
- }
- void OutPut(ofstream OutFile, myWord *Root[], int Count, char *p)
- {
- int i;
- for(i=0; i<Count; i++)
- {
- if (!Root[i]) continue;
- *p = Root[i]->myLetter;
- if (Root[i]->myCount)
- {
- *(p + 1) = 0;
- OutFile<<PubWord<<"\t\t"<<Root[i]->myCount<<endl;
- }
- OutPut(OutFile, Root[i]->Next, Count, p + 1);
- }
- }
- int main()
- {
- char InFileName[255];
- cout<<"input file name:";
- cin>>InFileName;
- ifstream InFile(InFileName);
- char Word[255];
- myWord * (Root[26]);
- for(int i=0; i<26; i++)
- {
- Root[i] = new myWord('a' + i);
- }
- while(ReadWord(InFile, Word))
- {
- CountWord(Root[int(*Word - (char)'a')], Word);
- }
- InFile.close();
- cout<<"\nOutput file name:";
- char OutFileName[255];
- cin>>OutFileName;
- ofstream OutFile(OutFileName);
- char *p = PubWord;
- OutPut(OutFile, Root, 26, p);
- OutFile.close();
- return 0;
- }
复制代码 |
|