Cuting off nul character

Cuting off nul character

Hi
in a QuickWin project, to get the name of a file to be oppened, I use
a subroutine containing the GETOPENFILENAME function.
The variable with the name of the file is defined to GETOPENFILENAME
in GGG%LPSTRFILE = LOC(NOMEARQ). NOMEARQ is declared in a module:

MODULE MODTRON

CHARACTER*255 NOMEARQ
LOGICAL TRONCO,INTERFERENCIA

END MODULE MODTRON

Another subroutine (wich also uses MODTRON) generates a OUTPUT.TXT file, with the filename,
obtained with GETOPENFILENAME, as a header.

To write the header I used:

OPEN(UNIT=5, FILE='C:PROJOUTPUT.TXT',FORM='FORMATTED')
WRITE(5,11)NOMEARQ
11 FORMAT(//,3X,'FILE: ',A25)

What is writen as the header, after 'FILE: ', is the filename appended with a nul character.
To get rid of the nul character I tried:

IL=LEN_TRIM(NOMEARQ)
OPEN(UNIT=5, FILE='C:PROJOUTPUT.TXT',FORM='FORMATTED')
WRITE(5,11)NOMEARQ(1,IL-1)
11 FORMAT(//,3X,'FILE: ',A25)

The nul character disapeared but 9 blanks were inserted before the filename.

What worked was:

CHARACTER*25 ARQD
.
.
.
IL=LEN_TRIM(NOMEARQ)
IRET=SYSTEMQQ('ECHO '//NOMEARQ(1:IL-1)//' > C:PROVPROV.TXT')
OPEN(UNIT=4, FILE='C:PROVPROV.TXT',FORM='FORMATTED')
READ(4,*) ARQD
CLOSE(4,DISP='DELETE')
OPEN(UNIT=5, FILE='C:PROJOUTPUT.TXT',FORM='FORMATTED')
WRITE(5,11)ARQD
11 FORMAT(//,3X,'FILE: ',A25)

This solution makes a hugly black DOS windows to appear for some seconds (due to SYSTEMQQ).
Is there an ellegant way of geting rid of the nul character? I have looked in online help but found nothing.

Thanks

Geraldo

6 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

In your first attempt to get rid of the null just replace

IL=LEN_TRIM(NOMEARQ)

with

IL=INDEX(NOMEARQ,CHAR(0))

and NOMEARQ(:IL-1) has what you want.

James

James

Using IL=INDEX(NOMEARQ,CHAR(0)) gives the same as in my first try:
NOMEARQ(:IL-1) is right justified in the A25 field and the 9 leading blanks I refered are the diference between
25 and the number of characters of a particular filename. Those leading blanks do not harm but it is not nice having

FILE: C:PROJECTXYZ.DAT
Instead of
FILE: C:PROJECTXYZ.DAT

Trying ADJUSTLEFT(NOMEARQ(:IL-1)) left justified it but inserted nul characters up to position 25.

What solved my problem was:

NOMEARQ(IL:25)=' '
WRITE(5,11)NOMEARQ(:25)
11 FORMAT(//,3X,'FILE: ',A25)

Thanks for your answer, it made me think a litle more.

Geraldo

Geraldo,

I thought but didn't say that you would also change the FORMAT statement from "A25" to "A". :-) Note that what is inserted in your case is not "nul" characters but spaces.

James

James,
I messed things and send twice the same reply.
As for changing the A format I will test.

Thanks again

Geraldo

James

Using IL=INDEX(NOMEARQ,CHAR(0)) gives the same as in my first try:
NOMEARQ(:IL-1) is right justified in the A25 field and the 9 leading blanks I refered are the diference between 25 and the number of characters of the particular filename
I used.
Those leading blanks do not harm but it is not nice having

FILE: C:PROJECTXYZ.DAT
Instead of
FILE: C:PROJECTXYZ.DAT

Trying ADJUSTLEFT(NOMEARQ(:IL-1)) left justified it but inserted nul characters up to position 25.
What solved my problem was:

NOMEARQ(IL:25)=' '
WRITE(5,11)NOMEARQ(:25)
11 FORMAT(//,3X,'FILE: ',A25)

Thanks for your answer, it made me think a litle more.

Geraldo

Login to leave a comment.