VC读取TXT文件数值

#include "iostream.h"
#include <stdio.h>
#include <stdlib.h>
#include <stdio.h>


void  main()
{
  FILE *file1=fopen("C://Documents and Settings//Administrator//桌面//新建文件夹//工程//yaoqiu//11.txt","r+");
    int ps=0,n=0;
   char ch=' ',ch1=' ';
   float f,m=0;
  char *str = new char();
   while ((ch= fgetc(file1))!= EOF)
 { 
    if(ch>47&&ch<58||ch==46)
    {
       if(ch1>47&&ch1<58||ch1==46)
         goto stop;
       else
         ps++;
            ch1=ch;
    }
    else
   stop: ch1=ch;
    //寻找最大浮点数;
  if(ch>47&&ch<58||ch==46)
       
    {str[n]=ch;
    n++;
    }
    else
    {
   f = atof(str);
             if(f>m) 
    m=f;
     for(int i=0;i<n;i++)
     {
     str[i]=' ';
     }
     n=0;
   
    }
  }

if(ch>47&&ch<58||ch==46)
    {
       if(ch1>47&&ch1<58||ch1==46)
         goto stop1;
       else
         ps++;
            ch1=ch;
    }
    else
   stop1: ch1=ch;
    //寻找最大浮点数;
  if(ch>47&&ch<58||ch==46)
       
    {str[n]=ch;
    n++;
    }
    else
    {
   f = atof(str);
             if(f>m) 
    m=f;
     for(int i=0;i<n;i++)
     {
     str[i]=' ';
     }
     n=0;
   
    }

     cout<<ps<<endl;
 cout<<m<<endl;
   //delete str;
    fclose(file1);
  
  
}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值