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 

Character Function Only Returns String of LEN=1

 
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> Support
View previous topic :: View next topic  
Author Message
viroxa



Joined: 28 Jul 2017
Posts: 69

PostPosted: Mon Aug 21, 2017 10:52 am    Post subject: Character Function Only Returns String of LEN=1 Reply with quote

Hello, everyone,

The following function only returns the first letter of the input string and I can't put my finger on why that is, so I'm asking for your advice once more.

And thanks a lot for all the help provided so far. It's made getting started with Fortran a lot less frustrating than I had it expected to be.

Code:

CHARACTER FUNCTION get_filepath(messg)
    CHARACTER FUNCTION get_filepath(messg)
    CHARACTER(LEN=260)::get_filepath,reval
    CHARACTER(LEN=*),INTENT(IN)::messg

!   Get filepath
    PRINT*,messg
    READ*,reval
    get_filepath=reval           
END FUNCTION get_filepath
Back to top
View user's profile Send private message
dgurok



Joined: 26 May 2011
Posts: 37

PostPosted: Mon Aug 21, 2017 1:05 pm    Post subject: Reply with quote

Do you have declared your variables outside of the function correctly?
Seems to work for me.

Code:
      PROGRAM TEST
C
      character*260 msg1,msg2,get_filepath
      msg1='test1'
      msg2='test2'
      msg1=get_filepath(msg2)
      write(*,*)'---'
      write(*,*)msg1
      END


Last edited by dgurok on Mon Aug 21, 2017 1:08 pm; edited 1 time in total
Back to top
View user's profile Send private message
mecej4



Joined: 31 Oct 2006
Posts: 732

PostPosted: Mon Aug 21, 2017 1:06 pm    Post subject: Reply with quote

A function or variable, declared to be of type CHARACTER, with no length specified, has a length of 1.

If that is not what you want, you must clearly stipulate what you wish to do, and declare the function to be of type CHARACTER(len=...), where the length can be a predetermined constant, or calculated in some way.
Back to top
View user's profile Send private message
viroxa



Joined: 28 Jul 2017
Posts: 69

PostPosted: Mon Aug 21, 2017 5:42 pm    Post subject: Reply with quote

Thanks!

I declared the variables correctly, but I didn't declare LEN=260 for get_filepath outside of the function.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> Support 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