View previous topic :: View next topic |
Author |
Message |
viroxa
Joined: 28 Jul 2017 Posts: 78
|
Posted: Mon Aug 21, 2017 10:52 am Post subject: Character Function Only Returns String of LEN=1 |
|
|
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 |
|
|
dgurok
Joined: 26 May 2011 Posts: 66
|
Posted: Mon Aug 21, 2017 1:05 pm Post subject: |
|
|
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 |
|
|
mecej4
Joined: 31 Oct 2006 Posts: 1885
|
Posted: Mon Aug 21, 2017 1:06 pm Post subject: |
|
|
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 |
|
|
viroxa
Joined: 28 Jul 2017 Posts: 78
|
Posted: Mon Aug 21, 2017 5:42 pm Post subject: |
|
|
Thanks!
I declared the variables correctly, but I didn't declare LEN=260 for get_filepath outside of the function. |
|
Back to top |
|
|
|