Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!cs.utexas.edu!ut-emx!reeder From: reeder@ut-emx.UUCP (William P. Reeder) Newsgroups: comp.lang.fortran Subject: length of a character string Keywords: null string, intrinsic function LEN Message-ID: <18585@ut-emx.UUCP> Date: 19 Sep 89 16:14:44 GMT Organization: University of Texas Computation Center Lines: 37 I was porting NCAR Graphics (version 2.01) to an Alliant yesterday when I got a compilation error on the third line of the following code fragment: character*80 ncarg call getenv('NCARGLIB', ncarg) if (ncarg.eq."") then A quick look in the standard confirmed that a character constant must contain one or more characters between the apostrophies. Yes, I know that those are quotes up there; NCAR must be assuming that all compilers allow quotes in place of apostrophies in addition to assuming that everyone allows null strings and lower case letters. Anyway, I need to check for a null string in variable "ncarg". I thought about using the intrinsic function LEN, but that just told me the size of the character variable (80), not the length of the string stored there (which may be less than 80). Is this the proper behavior for LEN? I can see where you would want to know how much storage was available in a character variable, but I want to know the length of a string stored in that variable much more frequently. I didn't see any standard intrinsic function defined which might give me this information. The best idea I have come up with so far for creating a "null" string is this: character*80 null write ( null, * ) Does anyone have any better ideas? -- William "Wills" Reeder, The University of Texas at Austin, Computation Center reeder@emx.utexas.edu, uunet!cs.utexas.edu!ut-emx!reeder, (512)471-3241 DISCLAIMER: Opinions expressed above are those of the author and do not necessarily reflect the opinions of The University of Texas at Austin, or those of the manufacturer of the wires which carried this message.