[Info-vax] C... the only winning move is not to play...
VAXman- at SendSpamHere.ORG
VAXman- at SendSpamHere.ORG
Mon Feb 10 10:43:58 EST 2014
In article <ldaq8t$l3k$1 at reader1.panix.com>, JohnF <john at please.see.sig.for.email.com> writes:
>{...snip...}
>> The John way:
>
>Nope...
> char *words[] = { "a", "is", ..., "\000" },
> *word, string[999]="\000";
> int length = 0;
> for ( word=words[0]; *word != '\000'; word++ ) {
> int len=strlen(word);
> if ( length+len >= 999 ) break; /* or realloc and cat */
> strcat(string,word); length+=len; }
>Or you could alloc/realloc string if you don't like
>that 999.
> But you already knew all that, right? You're just
>intentionally making it look harder that necessary,
>and maybe a little more vulgar than necessary, too
>(note: gratuitous vulgarity can sometimes be a
>giveaway as to what's going on).
No, I was trying to parallel my examples The declaration of the strings was
not part of the problem; only a way to demonstrate it. If I knew what each
part of each string was going to be -- as in your example, an array thereof
-- there would be no reason to even use concat.
The issue is that a number of strings exist as OpenVMS string descriptors.
I call upon STR$CONCAT to concatenate them because I don't know what each
string will be. The target string is defined as an OpenVMS dynamic string
descriptor so it can dynamically resize to whatever is needed to house the
concatenated parts. OpenVMS and, specifically, the RTL libraries, handle
the dynamic strings quite well.
STR$CONCAT(&sentence,&word1,&word2,...,&wordN);
...is a whole world easier on the eyes and more understandably readable
than:
int length = 0;
for ( word=words[0]; *word != '\000'; word++ ) {
int len=strlen(word);
if ( length+len >= 999 ) break; /* or realloc and cat */
strcat(string,word); length+=len; }
Anyway, your suggestion worked and for that I am grateful.
--
VAXman- A Bored Certified VMS Kernel Mode Hacker VAXman(at)TMESIS(dot)ORG
Well I speak to machines with the voice of humanity.
More information about the Info-vax
mailing list