读取txt文档中的数值,有一定的协议,读取后求和,并计算出平均值
2013-05-28 19:37
399 查看
// TODO: Add your control notification handler code here CFile file("11.txt",CFile::modeRead);//创建文件,关联路径和读取方式 char *pBuf; //定义字符指针,接收文档内容, int len=file.GetLength();//获取文件内容长度 pBuf=new char[len+1];//指针空间 file.Read(pBuf,len);//读取内容 pBuf[len]='\0';//字符串末字符 file.Close();//关闭文件 // MessageBox(pBuf); int sum=0;//求和 int count=0;//数据个数 for (int i=0;i<len;i++) { if (pBuf[i]=='A'&&pBuf[i+1]=='+')//协议格式 { count++; CString tmp; tmp+=pBuf[i+2]; tmp+=pBuf[i+3]; tmp+=pBuf[i+4]; tmp+=pBuf[i+5]; tmp+=pBuf[i+6]; tmp+=pBuf[i+7];读取格式后6为字符 int inttmp=atoi(tmp);字符串转化为整型 sum+=inttmp;//求和 } } CString s; s.Format("%d",sum/count);//求平均值 GetDlgItem(IDC_EDIT1)->SetWindowText(s);//显示
相关文章推荐
- JAVA写个东西读取TXT中的数据 且要计算出平均值和总值 最后还要按总值排序
- 读取txt文档中单词,并计算单词出现的次数(英文文档)
- 读取txt文档中单词,并计算单词出现的次数(英文文档)
- 作业训练------通过读取c.txt文件中的内容等号右值,并将右值的最大值、最小值、平均值打印到屏幕上。
- VTK读取一个TXT文档中的三维点坐标显示三维点云
- Shell-计算多行数值求和
- 从一个磁盘文件中读取数据计算平均值,最后把计算结果放到另一个磁盘文件中(fscanf(),fprintf()函数应用)
- valueForKeyPath计算求和、平均值、最大、最小
- 【转】java读取本地txt文档
- 彻底解决android读取中文txt的乱码(自动判断文档类型并转码
- Java读取txt文件,计算2011年9月份的通话时间
- C++读取txt文档内容并截取相应的字符串
- Java程序设计(十一)----计算的窗口求和求平均值
- 用javascript实现读取txt文档的脚本
- awk命令计算一列数值的总和,平均值,最大值,最小值
- matlab读取txt文档行数
- java读取txt文档
- Cocos2d—X游戏开发之 C++ MAP 读取策划、数值等文本文档
- rtsp协议相关之-rfc1889(RTP 实时应用传送协议文档).txt
- 文件读写 读取txt文档