Re: How to compare two strings in 77?




jane.sync@xxxxxxxxx wrote:
> I thought I could test two strings with the code below, but it doesn't
> work. I'm passing a string into the function below, but the result is
> always 'not equal'. How are strings compared in Fortran 77? Thanks.
>
> function evaluateinput(str1) result(string)
> implicit none
> character(12) str1
> character(12) string
> if (str1 .EQ. 'test') then
> string = 'equal'
> else
> string = 'not equal'
> endif
> return
> end

Well, certainly not in the above code, which is not FORTRAN 77. Try

CHARACTER*9 FUNCTION string ( str1 )
IMPLICIT NONE
CHARACTER*(*) str1
IF ( str1 .EQ. 'test' ) THEN
string = 'equal'
ELSE
string = 'not equal'
END IF
RETURN
END

Dave Flower

.



Relevant Pages

  • Re: Why doesnt join() call str() on its arguments?
    ... >>What I can't find an explanation for is why str.joindoesn't ... joinon actual strings, or all uses of adding arbitrarily typed ... Python as well. ... Explicit is better than implicit. ...
    (comp.lang.python)
  • Re: Setting Java Virtual Memory
    ... > You are probably instantiating too many objects. ... the implicit StringBuffer instances used to implement the += ... operator on Strings will never cause an OutOfMemoryError. ... collected before the error is thrown. ...
    (comp.lang.java.programmer)
  • Re: How to compare two strings in 77?
    ... Does the following code look like something a Fortran ... programmer would use to test two strings? ... implicit none ...
    (comp.lang.fortran)
  • Re: F77/C integration : strings
    ... the standard header for malloc is. ... pointer *value* to getString, which then stores the pointer to ... If you mean to treat this as CHARACTER*9 in Fortran you only need to ... Only if you want "hybrid" strings that have the padded value ...
    (comp.lang.fortran)
  • Re: Passing User Defined Types from VB to Fortran
    ... new front end using VB and have the VB code call the Fortran entry ... arrays of UDTs only - unable to figure out how to handle a large volume ... UDT with included strings and arrays. ...
    (comp.lang.fortran)