Re: How to compare two strings in 77?



jane.sync@xxxxxxxxx wrote:
I think I got it. Does the following code look like something a Fortran
programmer would use to test two strings?

      function evaluateinput(str1) result(string)
      implicit none
      character(12) str1
      character(12) string
      if (LLT(str1,'test')) then
        string = 'less than'
      else if (LGT(str1,'test')) then
        string = 'greater than'
      else
        string = 'equal'
      end if
      return
      end


I think you've found a work-around, not a fix. The problem is the declaration of str1. If you pass a string of length shoother than 12, (say, 5), then the characters of str1 from position 6 onwards will contain garbage. It is this garbage that prevents str1 from being equal to 'test'; but the collating operators (LLT and LGT) will still work.


The fix? Replace

character(12) str1

by

character(*) strl

cheers,

Rich
.



Relevant Pages

  • Re: memory leak or not?
    ... MyJonObject is not instanced in this method. ... string A = MyJonObject.ToString; ... As it had been a "normal" reference type the object would in my idea ... a pool somewhere so won't be garbage collected until the application ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Stupid Question - losing my mind - Garbage Collection and methods..
    ... > Will Garbage Collection clean up the String variable named test in the ... > method doSomething(String inme)? ... Garbage collect collects objects that have no references to them. ... string value "whatever". ...
    (comp.lang.java.programmer)
  • odbc_error() questions
    ... Testing the result can return a null string or sometimes a garbage ... Any ideas why I'm sometimes getting garbage back? ... Unable to lock table SQL (LOCK TABLE WEBSYS.FRTBNUM IN EXCLUSIVE ... time sometimes it outputs the error message and sometimes it doesn't. ...
    (comp.lang.php)
  • Re: Seems to be related to the debugger..
    ... I only get garbage when I use "Start Debugging". ... Is sSum declared as wstring, ... string is stored internally, deugger basically interpets first four bytes ...
    (microsoft.public.vc.atl)
  • Re: Seems to be related to the debugger..
    ... I only get garbage when I use "Start Debugging". ... Is sSum declared as wstring, ... implement small string optimization, ...
    (microsoft.public.vc.atl)