LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 627|回复: 2

这个程序为什么不能编译?

[复制链接]
发表于 2003-12-2 08:37:29 | 显示全部楼层 |阅读模式
我为了测试一下Windows和Linux下的C编译文件的大小,在Windows里写了一个C++的小程序,在VC6下编译通过,运行也正常,但换到Linux下无论是用gcc还是g++编译都不过,说是让我使用32位的库
把代码粘一下,哪位给看看


  1. //count.cpp

  2. #include <iostream.h>
  3. #include <fstream.h>

  4. char PubWord[255];

  5. class myWord
  6. {
  7. public:
  8.         myWord(){setNull();};
  9.         myWord(char Letter) {setNull(); myLetter = Letter;};
  10.         ~myWord(){for (int i=0; i<26; i++) {if (!Next[i]) {delete Next[i];}}};
  11.         void setNull(){myCount =0; for (int i=0; i<26; i++) {Next[i] = 0;}};
  12.         char myLetter;
  13.         int myCount;
  14.         myWord *(Next[26]);
  15. };

  16. int ReadWord(ifstream File, char * Word)
  17. {
  18.         char * r = new(char);
  19.         do{
  20.                 File.read(r, 1);
  21.                 if ((*r>='A') && (*r<='Z'))
  22.                 {
  23.                         *r += 'a' - 'A';
  24.                 }
  25.                 if (File.eof()) return 0;
  26.         }while(!(((*r>='a') && (*r<='z')) || (*r==0) || File.eof()));

  27.         if (*r)
  28.         {
  29.                 while (*(Word++) = *r)
  30.                 {
  31.                         if (File.eof()) break;
  32.                         File.read(r, 1);
  33.                         if ((*r>='A') && (*r<='Z'))
  34.                         {
  35.                                 *r += 'a' - 'A';
  36.                         }
  37.                         if ((*r>'z') || (*r<'a')) break;
  38.                 }
  39.                 *Word = 0;
  40.                 return 1;
  41.         }
  42.         else
  43.         {
  44.                 return 0;
  45.         }
  46. }

  47. void CountWord(myWord * Root, char * Word)
  48. {
  49.         if (*(++Word))
  50.         {
  51.                 char r = *Word;
  52.                 if (!(Root->Next[r-'a']))
  53.                 {
  54.                         Root->Next[r-'a'] = new myWord(r);
  55.                 }
  56.                 CountWord(Root->Next[r-'a'], Word);
  57.         }
  58.         else
  59.         {
  60.                 Root->myCount++;
  61.         }
  62. }

  63. void OutPut(ofstream OutFile, myWord *Root[], int Count, char *p)
  64. {
  65.         int i;
  66.         for(i=0; i<Count; i++)
  67.         {
  68.                 if (!Root[i]) continue;
  69.                 *p = Root[i]->myLetter;
  70.                 if (Root[i]->myCount)
  71.                 {
  72.                         *(p + 1) = 0;
  73.                         OutFile<<PubWord<<"\t\t"<<Root[i]->myCount<<endl;
  74.                 }
  75.                 OutPut(OutFile, Root[i]->Next, Count, p + 1);
  76.         }
  77. }

  78. int main()
  79. {
  80.         char InFileName[255];
  81.         cout<<"input file name:";
  82.         cin>>InFileName;
  83.         ifstream InFile(InFileName);

  84.         char Word[255];
  85.         myWord * (Root[26]);
  86.         for(int i=0; i<26; i++)
  87.         {
  88.                 Root[i] = new myWord('a' + i);
  89.         }
  90.         while(ReadWord(InFile, Word))
  91.         {
  92.                 CountWord(Root[int(*Word - (char)'a')], Word);
  93.         }
  94.         InFile.close();

  95.         cout<<"\nOutput file name:";
  96.         char OutFileName[255];
  97.         cin>>OutFileName;
  98.         ofstream OutFile(OutFileName);
  99.         char *p = PubWord;
  100.         OutPut(OutFile, Root, 26, p);
  101.         OutFile.close();
  102.         return 0;
  103. }
复制代码
发表于 2003-12-2 22:55:28 | 显示全部楼层

把参数改成传引用就可以了

如题
 楼主| 发表于 2003-12-5 20:04:58 | 显示全部楼层
不是这个问题,系统提示是库应该使用32位什么什么的.而且程序在windows2000下用vc6编译和运行是可以通过的
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表