Home > Archive > Fortran > April 2006 > How to Add NULL Character to end of CHAR Variable
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
How to Add NULL Character to end of CHAR Variable
|
|
| tornado Jeff 2006-04-16, 10:03 pm |
| All,
My routine is doing a formatted read of a character string from a file
to the character variable CFOO and I need to add a NULL character to
the end of that character string within CFOO. How is that done?
Thanks in advance,
Jeff
| |
| Dan Nagle 2006-04-16, 10:03 pm |
| Hello,
If you do not consider any trailing blanks to be part of the string,
then try something like
end_char = len_trim( cfoo) + 1
cfoo( end_char: end_char) = char( 0)
tornado Jeff wrote:
> All,
>
> My routine is doing a formatted read of a character string from a file
> to the character variable CFOO and I need to add a NULL character to
> the end of that character string within CFOO. How is that done?
>
> Thanks in advance,
> Jeff
>
--
Cheers!
Dan Nagle
Purple Sage Computing Solutions, Inc.
| |
| tholen@antispam.ham 2006-04-16, 10:03 pm |
| tornado Jeff writes:
> My routine is doing a formatted read of a character string from a file
> to the character variable CFOO and I need to add a NULL character to
> the end of that character string within CFOO. How is that done?
CHARACTER*1 Null
Null = CHAR(0)
NewString = CFoo//Null
Declare NewString with a length one longer than CFoo. Slight variation
on the above if you need to position the null after the last non-blank
character.
| |
|
| "Dan Nagle" <dannagle@verizon.net> wrote in message
news:gKt0g.1953$V73.410@trnddc06...
> Hello,
>
> If you do not consider any trailing blanks to be part of the string,
> then try something like
>
> end_char = len_trim( cfoo) + 1
> cfoo( end_char: end_char) = char( 0)
This will produce a string error in the case
where the final character of cfoo is non-blank, for it attempts
to store a character beyond the defined length.
| |
| Dan Nagle 2006-04-17, 7:03 pm |
| Hello,
robin wrote:
> "Dan Nagle" <dannagle@verizon.net> wrote in message
> news:gKt0g.1953$V73.410@trnddc06...
>
> This will produce a string error in the case
> where the final character of cfoo is non-blank, for it attempts
> to store a character beyond the defined length.
And which part of "something like" produces the error?
Is Robin still picking fights with folks who actually use Fortran?
What, a slow day in PL/I land?
--
Cheers!
Dan Nagle
Purple Sage Computing Solutions, Inc.
| |
| Rich Townsend 2006-04-17, 7:03 pm |
| Dan Nagle wrote:
> Hello,
>
> robin wrote:
>
>
>
> And which part of "something like" produces the error?
>
> Is Robin still picking fights with folks who actually use Fortran?
> What, a slow day in PL/I land?
>
No, just a slow PL/I user.
;)
| |
| David Frank 2006-04-17, 7:03 pm |
|
"tornado Jeff" <jkrob@comcast.net> wrote in message
news:1145196648.052905.256820@t31g2000cwb.googlegroups.com...
> All,
>
> My routine is doing a formatted read of a character string from a file
> to the character variable CFOO and I need to add a NULL character to
> the end of that character string within CFOO. How is that done?
>
> Thanks in advance,
> Jeff
>
I am surprised no-one posted a 1 line answer..
cfoo = trim(cfoo) // char(0)
if cfoo has a non-blank char in its last char, above results in a
no-operation,
(the concatenated null is lopped-off in the assignment)
..
|
|
|
|
|