CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
IBM Rational 系统开发最佳实践工具包 WebSphere MQ 最佳实践 TOP 15
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  C/C++ >  C++ 语言

请问怎么得到abc.txt内的数量?

楼主z126726a()2006-03-04 01:25:45 在 C/C++ / C++ 语言 提问

FILE   *fp;  
  fp=fopen("abc.txt",   "r");  
  .......  
   
  abc里面是四个1,怎么才得到里面的数量呢?如果太多的话是不可能静态指定的啊 问题点数:30、回复次数:6Top

1 楼ostrich2fly(ostrich2fly)回复于 2006-03-04 08:18:34 得分 0

没看明白什么意思  
  Top

2 楼jobs002(Oh! Office)回复于 2006-03-04 08:24:41 得分 0

ifstream   fin("test.txt");  
  int   GetFromFile[100];  
  int   m;  
  fin>>GetFromFile;  
  m=sizeof(GetFromFile)/sizeof(m);  
  Top

3 楼vcmute(BCare4 H1Rest Good9!)回复于 2006-03-04 09:46:00 得分 0

fseek(fp,0,SEEK_END);  
  int   filelen=ftell(fp);Top

4 楼84shelley(影朔)回复于 2006-03-04 10:11:30 得分 0

这个类定义了一组文本操作,具体用到什么你自己看  
  //Text.h  
   
  #ifndef   _INC_TEXT  
  #define   _INC_TEXT  
  /////////////////////////////  
  //类名:CText  
  //作者:shelley  
  //最后修改时间:2005/02/03  
  //说明:提供对文本的基础操作,并作为基类为其他基于文本的类提供基本组成功能  
  ////////////////////////////  
  class   CText      
  {  
  public:  
  CText();  
  virtual   ~CText();  
  public:  
  CString   GetText(void);  
   
  BOOL   OpenText(void);  
   
  UINT   GetRowCount(void);  
  char*   GetCurrentPointer(void);  
  UINT   GetCharCount(char   flag);//获取指定字符个数  
  char*   GetCharPointer(char   flag,   int   no);//返回指定字符的指针,如果返回为NULL则表示操作失败,第二个参数表示要查找的字符存在的个数,其最小值为1。  
  protected:  
  CString   m_strFileName;  
  CString   m_strFilePath;  
  CFile   *m_pFile;  
  BOOL   m_bOpen;  
  char   *m_pBuf;  
  char   *lpBuf;  
  char   *m_pEndBuf;  
  UINT   m_RowCount;  
  protected:  
  BOOL   CloseText(void);  
  void   MoveToBegin(void);  
  inline   UINT   RowCount(void);//仅提供类及子类的OpemText()使用  
  CString   GetChars(UINT   begin,   UINT   end);  
  BOOL   IsOpen(void);  
  BOOL   NextRow(void);  
  };  
  #endif   //_INC_TEXT  
   
  //Text.cpp  
  //////////////////////////////////////////////////////////////////////  
   
  #include   "stdafx.h"  
  #include   "..\AudioDataBase.h"  
  #include   "Text.h"  
   
  #ifdef   _DEBUG  
  #undef   THIS_FILE  
  static   char   THIS_FILE[]=__FILE__;  
  #define   new   DEBUG_NEW  
  #endif  
   
  //////////////////////////////////////////////////////////////////////  
  //   Construction/Destruction  
  //////////////////////////////////////////////////////////////////////  
   
  CText::CText()  
  {  
  //m_strFileName   =   FileName;  
  //m_strFilePath   =   FilePath;  
  m_bOpen   =   FALSE;  
  m_pFile   =   new   CFile();  
  m_pBuf   =   (char*)malloc(sizeof(char)*65535);  
  m_pEndBuf   =   &m_pBuf[65534];  
  }  
   
  CText::~CText()  
  {  
  //m_pFile->Close();  
  delete   m_pFile;  
  free(m_pBuf);  
  }  
   
  BOOL   CText::OpenText(void)  
  {  
  if   (IsOpen())  
  {  
  this->CloseText();  
  }  
  CString   temp   =   this->m_strFilePath+"\\"+this->m_strFileName;  
  if   (m_pFile->Open(temp,   CFile::modeRead))  
  {  
  m_bOpen   =   TRUE;  
  m_pFile->Read(m_pBuf,   65535);  
  lpBuf   =   m_pBuf;  
  m_RowCount   =   RowCount();  
  return   TRUE;  
  }  
  return   FALSE;  
  }  
   
  BOOL   CText::CloseText(void)  
  {  
  if   (!IsOpen())  
  {  
  return   FALSE;  
  }  
  m_pFile->Close();  
  return   TRUE;  
  }  
   
  CString   CText::GetText(void)  
  {  
  if   (!IsOpen())  
  {  
  this->OpenText();  
  }  
  return   lpBuf;  
  }  
   
  BOOL   CText::IsOpen()  
  {  
  return   m_bOpen;  
  }  
   
  BOOL   CText::NextRow()  
  {  
  if   (!IsOpen())  
  {  
  this->OpenText();  
  }  
  while   (*lpBuf!=13)  
  {  
  lpBuf++;  
  if   (lpBuf==m_pEndBuf)  
  {  
  return   FALSE;  
  }  
  }  
  lpBuf   +=   2;  
  return   TRUE;  
  }  
   
  char*   CText::GetCharPointer(char   flag,   int   no)  
  {  
  if   (no>GetCharCount(flag))  
  return   NULL;  
  if   (no<1)  
  no   =   1;  
  char   *pTemp;  
  pTemp   =   lpBuf;  
  for   (UINT   i=0;   i<no;   i++)  
  {  
  while   ((*pTemp!=flag)&&(*pTemp!=0))  
  {  
  pTemp++;  
  }  
  pTemp++;  
  }  
  pTemp--;  
  return   pTemp;  
  }  
   
  UINT   CText::GetCharCount(char   flag)  
  {  
  if   (!IsOpen())  
  {  
  this->OpenText();  
  }  
  UINT   Count   =   0;  
  char   *pTemp;  
  pTemp   =   m_pBuf;  
  while   (*pTemp!=0)  
  {  
  if   (*pTemp==flag)  
  {  
  Count++;  
  }  
  pTemp++;  
  }  
  return   Count;  
  }  
   
  void   CText::MoveToBegin(void)  
  {  
  if   (!this->IsOpen())  
  {  
  this->OpenText();  
    }  
  lpBuf   =   m_pBuf;  
  }  
   
  char*   CText::GetCurrentPointer(void)  
  {  
  if   (!this->IsOpen())  
  {  
  this->OpenText();  
  }  
  return   lpBuf;  
  }  
   
  UINT   CText::GetRowCount(void)  
  {  
  if   (!this->IsOpen())  
  {  
  this->OpenText();  
  }  
  return   m_RowCount;  
  }  
   
  UINT   CText::RowCount(void)  
  {//内部功能模块函数  
  UINT   Count   =   0;  
  char   *temp;  
  temp   =   lpBuf;  
  while   (*temp!=0)  
  {  
  if   (*temp==13)  
  {  
  Count++;  
  }  
  temp++;  
  }  
  return   Count;  
  }  
   
   
  CString   CText::GetChars(UINT   begin,   UINT   end)  
  {  
  if   (end<begin)  
  {  
  return   "";  
  }  
  if   (!IsOpen())  
  {  
  this->OpenText();  
  }  
  char   *temp;  
  char   *Buf;  
  temp   =   (char*)malloc(sizeof(char)*65535);  
  Buf   =   (char*)malloc(sizeof(char)*65535);  
  CString   str   =   this->GetText();  
  strcpy(Buf,   str);  
  CString   Chars   =   "";  
  for   (int   i=0;   i<(end-begin);   i++)  
  {  
  temp[i]   =   Buf[begin+i];  
  }  
  temp[i]   =   0;  
  Chars   =   temp;  
  free(Buf);  
  free(temp);  
  return   Chars;  
  }Top

5 楼zengwujun(月之海 为linux入门奋斗100天)回复于 2006-03-04 10:52:44 得分 0

FILE   *fp;  
  fp=fopen("abc.txt",   "r");  
  char   sz[8];  
  fread(sz,   sizeof(int),   1,   fp);  
  int   cnt   =   atoi(sz);  
   
  如果有多个整数,就循环处理,并用fseek定位Top

6 楼skfox(sky)回复于 2006-03-04 15:16:40 得分 0

没明白lz的意思Top

相关问题

  • 如何得到TServerSocket.Socket.Connections的数量?
  • ComBox中items的数量如何得到
  • 如何得到库存数量
  • myname.asp?abc 我怎么得到这个 "abc"
  • 不使用mysql_num_rows得到rows的数量该怎么做
  • 怎样才能得到一个文件中记录的数量?
  • POP3 STAT 命令无法得到邮件数量的问题==>
  • 如何用VB得到W2K的物理内存数量?
  • 请问如何得到本机串口的数量
  • 如何得到磁盘分区的数量,抢分题!

关键词

  • 字符
  • 文本
  • ctext
  • opentext
  • getfromfile
  • isopen
  • pbuf
  • ptemp
  • uint
  • lpbuf

得分解答快速导航

  • 帖主:z126726a

相关链接

  • C/C++ Blog
  • C/C++类图书
  • C/C++类源码下载

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
北京创新乐知广告有限公司 版权所有, 京 ICP 证 070598 号
世纪乐知(北京)网络技术有限公司 提供技术支持
Copyright © 2000-2008, CSDN.NET, All Rights Reserved
GongshangLogo