Re: ISO_C_BINDING and C strings conversion
- From: GaryScott <garylscott@xxxxxxxxxxxxx>
- Date: Thu, 20 Jan 2011 09:29:08 -0800 (PST)
On Jan 20, 11:06 am, nos...@xxxxxxxxxxxxx (Richard Maine) wrote:
Gary L. Scott <garylsc...@xxxxxxxxxxxxx> wrote:
I typically just delete the null(s) from the C string (replace with a
space character)...my procedure is called "deletenulls" (not really a
conversion so much as a kludging)
That description might be misleading me, but I'd normally expect to have
to replace not just the null(s), but everything after the first null.
If it is a "proper" C string, then there should be only one null, with
nothing after it, but your (s) makes me assume this isn't always the
case for what you are talking about.
If it is a C string stored in some fixed-size Fortran string or array,
then there might well be garbage after the first null. You then need to
replace all that garbage with blanks - not just the pieces that happen
to be null. Otherwise, you get garbage in your result. Been there; done
that; have also fixed that bug in other people's code.
Richard Maine | Good judgment comes from experience;
email: last name at domain . net | experience comes from bad judgment.
domain: summertriangle | -- Mark Twain
Of course. I typically initialize to blanks before using a string.
I've never had a properly functioning C procedure overwrite anything
beyond the null character in my always long-enough buffer, but I
suppose its possible.
- Prev by Date: Re: "parameter" fields in derived types
- Next by Date: Re: "parameter" fields in derived types
- Previous by thread: Re: ISO_C_BINDING and C strings conversion
- Next by thread: Re: ISO_C_BINDING and C strings conversion