MSN 講完之後想想還是來貼一下好了, 畢竟最近幾年忙的亂七八糟, 好長一段時間都沒在這裡胡言亂語了. 下面是兩個互轉的範例, 網頁上貼東西好像位置會歪掉, 剪貼進 F77 的時候前面空格數目要留心一下, 要不然會 compile 失敗.
1. String to Integer (str2int.f)
integer i
character*80 str
write(*,*) 'input a string: '
read(*,*) str
read(str,*) i
write(*,FMT='(A A)') 'the string is: ', str
write(*,*) 'the integer is: ', i
stop
end
2. Integer to String (int2str.f)
integer i
character*80 str
i=1
write(*,*) 'input a integer: '
read(*,*) i
write(str, FMT='(I5)') i
write(*,*) 'the integer is: ', i
write(*,FMT='(A A)') 'the string is: ', str
stop
end
No comments:
Post a Comment