简体   繁体   中英

Fortran77: Checking if character array index is empty

I have a character array names(10)*6 . I'm looping through I = 1:10 and writing the values of names(I).

The problem is that names periodically is missing values, and if thats the case for a particular names(I) , I want to skip it.

I was trying to do something like this.

   IF(names(I) .NE. 0) THEN 
        WRITE(4,202) names(I)   
    ENDIF

I got an error telling me I'm dumb for comparing characters to 0. That makes sense. What should I compare it to? Empty spaces like this? How do I check if its not defined or empty after I declared space for it?

IF(mychar(I) .NE. '      ') THEN 
     WRITE(4,202) names(I)  
ENDIF

The goal is to only issue the write command if there is actually something there. :-)

Edit Note: I may not initialize this array. I am wondering what the default value for an undefined declared index is, or if there is a function to check if a character array index is empty.

You might be interested in the intrinsic len_trim function. As always Read The Fortran Manual.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM