增加数据读取(无法正确显示四位数?)


#include "fstream.h"
#include "math.h"

#define max_len 3600
//每个周期测360个点

//using namespace std;


void rFile(char *fID)
{
// cout<<"接口测试:得到文件名"<<fID<<"。"<<endl;
 ifstream fin(fID);//打开文件
 char datac[max_len];
 for(int r=0;r<=max_len;r++)
 {
  fin>>datac[r];//逐位读取文件内容,得到数组
  if(datac[r]==' ')
  {
   r++;
  }
 }
 
 
 long datai[max_len];//根据数据特征,每三位数字合成一个三位数
 int i0=0;
 int mark;
 mark=(datac[0]-48)*100+(datac[1]-48)*10+(datac[2]-48);//第一个数据为标号
 
 ///四位数?
 ///
 for(int i=6;i<=max_len;i+=3,i0++)
 {
  if(datac[i-2]=='1')
  {
   i++;
   datai[i0]=1000+(datac[i-2]-48)*100+(datac[i-1]-48)*10+(datai[i]-48);//首位为1则判断为4位数
  }
  datai[i0]=(datac[i-2]-48)*100+(datac[i-1]-48)*10+(datac[i]-48);//实际值为ASC2码-48

 }
 

 cout<<"接口测试:读取文件内容"<<endl;

  for(int j=0;j<int(max_len/3);j++)
 {
  cout<<datai[j]<<" ";

 }
 cout<<endl;


}
/*
int slen(char *a)//获取字符串数组长度
{
 int i;
 for(i=0;a[i]!='/0';i++)
 {
  ;
 }
 return i;
}
*/
void jus()//判断语句
{
 char just;
 char fID[20];

 for(int i=0;;i++)
 {
  cout<<"输入要读取的文件(含后缀):";
  cin>>fID;
  cout<<"读取文件"<<fID<<"。确定(y)?";
  cin>>just;
  if(just=='y')
  {
   rFile(fID);
  }
  
 }
 
}

void main()
{
 jus();
 
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值