- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi
I am somewhat baffled by this behaviour. I have this program
It seems that the string ' ' (8 spaces) is being incorrectly
flagged as being equal to '' (NULL string)
I am completely baffled by this!!
Any insight would be most welcome
Geoff
I am somewhat baffled by this behaviour. I have this program
PROGRAM LoadOfRubbish
INTERFACE
SUBROUTINE IsAnything( NAME)
CHARACTER(LEN=*), OPTIONAL :: NAME
END SUBROUTINE
END INTERFACE
CALL IsAnything( NAME = '--------' )
CALL IsAnything( NAME = ' ' )
CALL IsAnything( NAME = '' )
END
SUBROUTINE IsAnything ( NAME )
CHARACTER(LEN=*), OPTIONAL :: NAME
IF(PRESENT(NAME)) THEN
WRITE(*,'(A)') NAME
WRITE(*,*) LEN(NAME)
IF(NAME .EQ. '') WRITE(*,*) 'WOOPS'
END IF
RETURN
END
When I run it I get the following output
--------
8
8
WOOPS
0
WOOPS
It seems that the string ' ' (8 spaces) is being incorrectly
flagged as being equal to '' (NULL string)
I am completely baffled by this!!
Any insight would be most welcome
Geoff
Link Copied
2 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Standard Fortran behavior. When you compare strings of unequal lengths, the shorter string is padded on the right with blanks as necessary.
Steve
Steve
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Steve
Thanks. Sorry to waste your time.
Geoff
Thanks. Sorry to waste your time.
Geoff
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page