D
Dave Thompson
Right. Or at least that's what he asked for. Based on past behavior inSince writing a C program to output "123" is trivial, I assume
you're wanting to write a C function that takes a string such as
'123' and encloses it in quotes: '"123"', like that.
comp.lang.fortran and .pl1 it is unlikely David Frank *wants* to do
anything useful or even correct.
In "basic" Fortran (ISO/IEC 1539-1:1997 aka F95) character strings areI don't know what 'trim(s1)' does, but I'll assume that 'trim' is
a no-op in this context.
fixed length, (right) padded with blanks. It is often necessary to
remove those blanks, and the instrinsic (builtin) function TRIM does
that, while LEN_TRIM returns the number of characters in a string
excluding trailing blanks i.e. the "valid" length. (An optional "part"
1539-2 adds dynamically varying strings, like C++ std::string or Ada
Unbounded_String or any number of heapptr+count(s) C packages.)
In his example *usage* the (actual) argument is a string literal,
hence (exact length) unpadded, so TRIM was a no-op. More generally it
would have been used on a variable and the TRIM would matter.
So three ways of doing this are <snip usual suspects>
It is true that Fortran has an advantage in this area, in that it can
return as a value an array or a character string -- and in Fortran
like PL/1 and COBOL but unlike C, Pascal and Ada character string is a
distinct type not just array of character -- including with certain
limitations dynamically-determined sizes/lengths of same, without the
programmer having to manage storage allocation. C "don't do dat". You
can work around it more or less well, or bypass it by using your own
string package, but it remains a (tolerable) deficiency.
- David.Thompson1 at worldnet.att.net