1230431 发表于 2015-2-1 16:33:36

如何读取顺序不确定的文件?

请教各路大神一个问题:
我有如下这样一个txt文件(每一行中都没有空格,且行与行是随机存储的,并不是说第一行就是现在看到的内容,也有可能是第三行的内容):
报错文件名称 = Error.txt
提醒文件名称=Warn.txt
运行状态文件名称=FunState.txt
取消执行文件名称=FunCancel.txt
运行时间文件名称=FunTime.txt
我现在需要将该文件里的内容读出来,然后对每一行进行处理:通过等号左边的内容来判断等号右边的内容应该放到哪个变量中。

谢谢!!!



fcode 发表于 2015-2-1 19:53:29

Program www_fcode_cn
Implicit None
Character(len=256) :: c , cname , cvalue , a , b
Integer :: ierr , k
Open( 12 , File = '文件名' )
Do
    Read( 12 , "(a256)" , ioStat = ierr ) c
    If ( ierr /= 0 ) exit
    k = index( c , "=" )
    cname = c( : k-1 )
    cvalue = c( k+1 : )
    If ( cname == "报错文件名称" ) then
      a = cvalue
    Else If ( cname == "提醒文件名称" ) then
      b = cvalue
    End If
End Do
Close( 12 )
End Program www_fcode_cn

1230431 发表于 2015-2-1 21:54:27

fcode 发表于 2015-2-1 19:53
Program www_fcode_cn
Implicit None
Character(len=256) :: c , cname , c ...

thanks!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
页: [1]
查看完整版本: 如何读取顺序不确定的文件?