读入文件为什么程序会是死循环

lizr2006 2006-08-05 11:14:44
file.open(FileName);
while (!file.eof())
{
file.getline(Line,600);
int iKind = LineKind(Line);
physiccounter++;
if (4 == iKind)
{
codecounter++;
}
else if (1 == iKind)
{
commentcounter++;
}
/* else if (2 == iKind)
{
commentcounter++;
file.getline(Line,600);
iKind = LineKind(Line);
if (3 != iKind)
{
file.getline(Line,600);
}
}*/
}
file.close();
...全文
145 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
CExp001 2006-08-05
  • 打赏
  • 举报
回复
看不出来,关注
Dong 2006-08-05
  • 打赏
  • 举报
回复
看看
int r = file.getline(Line,600);的结果r是多少!
Dong 2006-08-05
  • 打赏
  • 举报
回复
不可能吧,所有代码呢?
lizr2006 2006-08-05
  • 打赏
  • 举报
回复
很多都是没什么用的 还正在写代码行统计程序
请大家多多指教 谢谢!
lizr2006 2006-08-05
  • 打赏
  • 举报
回复
// LineCount.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <stdio.h>
#include <errno.h>
/*for directroy funcgion */
#include <iostream>
#include <vector>
#include <string>
#include <iomanip>
#include <fstream>
#include "Function.h"
//#define _LINUX


#include <windows.h>

const char DefFileName[] = "C:\\test.txt";
const char LineOfPhysic[] = "Physic Line";
const char LineOfCode[] = "Code Line";
const char LineOfComment[] = "Comment Line";

using namespace std;

int OutPut(char *,char *,int);
BOOL ProcessFile( char * );


int main(int argc ,char **argv)
{

ProcessFile("StdAfx.cpp");
cout << endl;
return 0;
}

int LineKind(char *Line)
{
int Len = strlen(Line);
for (int i = 0; i < Len; i++)
{
if ( ' ' == Line[i])
{
continue;
}
else if ((('/' == Line[i]) && ('/' == Line[i+1])))
{
return 1;//注释行
}
else if ((('/' == Line[i]) && ('*' == Line[i+1])))
{
return 2;//"/*"开始
}
else if ((('*' == Line[i]) && ('/' == Line[i+1])))
{
return 3;//"*/"结束
}
else
{
return 4;//代码行
}
}
return 5;//空行
}

BOOL ProcessFile( char *FileName)
{
int codecounter =0; //代码行计数
int commentcounter = 0; //注释行计数
int physiccounter = 0; //物理行计数
char Line[600];
ifstream file ;//(FileName, ios::in);
/*if (! file)
{
cerr << "can't open input file \"" << FileName << "\""<< endl;
return FALSE;
}*/

// char c;
file.open(FileName);
while (!file.eof())
{
file.getline(Line,600);
int iKind = LineKind(Line);
physiccounter++;
if (4 == iKind)
{
codecounter++;
}
else if (1 == iKind)
{
commentcounter++;
}
/* else if (2 == iKind)
{
commentcounter++;
file.getline(Line,600);
iKind = LineKind(Line);
if (3 != iKind)
{
file.getline(Line,600);
}
}*/
}
file.close();

cout << (char *)&LineOfPhysic << " Of " << FileName << "is: " << physiccounter <<endl;
cout << (char *)&LineOfCode << " Of " << FileName << "is: " << codecounter <<endl;
cout << (char *)&LineOfComment << " Of " << FileName << "is: " << commentcounter <<endl;
return TRUE;
}
以上为所有代码, 谢谢大家!

64,676

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧