Re: removing chars from c strings

David: Thanks for the example.

For info, this works under Intel Fortran, ifort V9.x as well, but
with the warning message:

Warning: DFRemoveCh.f90, line 15: A DEC Fortran pointer variable has been explicitly
given a data type that is not the longest integer type associated with the current
platform. [SLOC]
integer :: nc, sloc ; pointer (sloc,a)
27 | The quick brown fox jumps |

Skip Knoble

On Tue, 18 Apr 2006 06:18:04 GMT, "David Frank" <dave_frank@xxxxxxxxxxx> wrote:

-|I posted below in comp.lang.pl1 and thought it might be informative here.
-|=========== begin snip ==============
-|I discovered CVF compiler allows a dynamic pointer connection,
-|and function below uses it to allow pack function to accept a string arg.
-|I dont recall seeing code using this technique before, and will make an
-|in comp.lang.fortran about whether my use shows something not seen before.
-|! -------------------------
-|PROGRAM varying_cstring
-|integer :: n
-|character(100) :: s = ' The qu*ick brown fox ju**mps 'C
-|n = Remove_Ch(s,'*')
-|write (*,*) n,' |',s(1:n),'|'
-|stop ! outputs 27 | The quick brown fox jumps |
-|! ----------------------
-|FUNCTION Remove_Ch(s,ch) RESULT (nc)
-|character(*) :: s
-|character :: ch, a(len(s))
-|integer :: nc, sloc ; pointer (sloc,a)
-|sloc = loc(s) ! dynamic connection a -> s
-|a = pack(a, a/=ch)
-|nc = index(s,char(0)) -1