- 积分
- 66
- 贡献
-
- 精华
- 在线时间
- 小时
- 注册时间
- 2014-9-2
- 最后登录
- 1970-1-1
|
楼主 |
发表于 2014-11-28 15:55:39
|
显示全部楼层
module constant
implicit none
integer n,nmax,cnum
character(*):: filename
character*1 sign
integer count
integer error
end module constant
module dealfile
use constant
contains
subroutine totalnum(filename,count,nmax,sign,cnum(:))
integer count,nmax,i,n,tonum
character*1 buffer(1:nmax)
character*1 sign
character,allocatable :: string(:)
integer,allocatable :: cnum(:)
open(10,file=filename)
allocate(string(n))
allocate(cnum(n))
do n=1,count
READ(10,100) string(n)
100 format(<nmax>A1)
write(*,*)string(n)
buffer=string(n)
cnum(1)=1
do i=1,nmax-1
if((buffer(i)==sign) .AND. (buffer(i+1)/=sign)) cnum(n)=cnum(n)+1
end do
tonum=tonum+cnum(n)
end do
close(10)
end subroutine totalnum
end module dealfile
program main
use constant
use dealfile
character line
print*,'文件名:'
read*,filename
count=0
open(10,file=filename,status='old')
do while (.true.)
read(10,*,iostat=error) line
if(error/=0)exit
count=count+1
end do
close(10)
print*,'行数:'
write(*,*)count
print*,'行的最大列数:'
read*,nmax
print*,'分隔符:'
read(*,100),sign
100 format(A1)
call totalnum(filename,count,nmax,sign,cnum(n))
print*,tonum
end program
能帮我看看错在哪里吗···· |
|