replica nfl jerseysreplica nfl jerseyssoccer jerseyreplica nfl jerseys forums.silverfrost.com :: View topic - Student exercise
forums.silverfrost.com Forum Index forums.silverfrost.com
Welcome to the Silverfrost forums
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Student exercise

 
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> General
View previous topic :: View next topic  
Author Message
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 8210
Location: Salford, UK

PostPosted: Thu Aug 15, 2013 10:02 am    Post subject: Student exercise Reply with quote

It would be nice if we had a Fortran function in the library that takes a character variable and translates C escape characters (\n, \r, \t etc.).

If you are a Fortran teacher, this might be a useful exercise for your students.

Here is a possible solution. Can it be improved?

Code:
function esc(str)
character(*) esc,str
character ce,cs
integer le,ls,ne,ns
le = len(esc)
ls = len(str)
ne = 1
ns = 1
do while(.TRUE.)
 cs = str(ns:ns)
 select case(cs)
   case("\")
     ns = ns + 1
     cs = str(ns:ns)
     select case(cs)
       case("\")
         ce = cs
       case("n")
         ce = char(10)
       case("r")
         ce = char(13)
       case("t")
         ce = char(9)
       case default
         esc(ne:ne) = "\"
         ne = ne + 1
         ce = cs
     end select
   case default
     ce = cs
 end select
 esc(ne:ne) = ce
 ne = ne + 1
 ns = ns + 1
 if(ns > ls .OR. ne > le) exit 
end do
if(ne <= le) esc(ne:) = " "
end

program test
character(len=256),external::esc
print*, trim(esc("Testing\tTesting"))
end
Back to top
View user's profile Send private message AIM Address
Display posts from previous:   
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> General All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group