Something like string-streams existing in "C"?

Liste des GroupesRevenir à cl c  
Sujet : Something like string-streams existing in "C"?
De : janis_papanagnou+ng (at) *nospam* hotmail.com (Janis Papanagnou)
Groupes : comp.lang.c
Date : 19. Dec 2024, 02:30:18
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <vjvsvb$2i07u$1@dont-email.me>
User-Agent : Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0
Inspecting some of my "C" source code here I noticed a construct that
I dislike...

    static char buf[32];   // sufficient space for ansi sequence
    ...
    sprintf (buf, "\033[38;5;%dm%c\033[0m", ...);

In case of known or deducible string sizes I'm preferring and using
some of the alloc() functions. In the sample I can at least deduce an
upper-bound for the buffer-size. But it's anyway still an undesired
hard-coded buffer size that I'd like to avoid.

I recall that in C++ I used "String-Streams" for dynamically extended
strings. But in "C" my reflex (and habit) is to write things like the
above code.

Is there something in "C" that allows dynamic flexibility of strings?
(Or are there other options that an experienced "C" programmer would
use instead?)

(If there's something available only with newer C-standards I'd also
appreciate a hint.)

Janis

Date Sujet#  Auteur
19 Dec 24 * Something like string-streams existing in "C"?15Janis Papanagnou
19 Dec 24 +- Re: Something like string-streams existing in "C"?1Keith Thompson
19 Dec 24 +- Re: Something like string-streams existing in "C"?1Lawrence D'Oliveiro
19 Dec 24 +* Re: Something like string-streams existing in "C"?11BlueManedHawk
19 Dec 24 i`* Re: Something like string-streams existing in "C"?10Kaz Kylheku
19 Dec 24 i `* Re: Something like string-streams existing in "C"?9Michael S
19 Dec 24 i  `* Re: Something like string-streams existing in "C"?8Kaz Kylheku
20 Dec 24 i   +* Re: Something like string-streams existing in "C"?6Thiago Adams
20 Dec 24 i   i`* Re: Something like string-streams existing in "C"?5Michael S
20 Dec 24 i   i +* Re: Something like string-streams existing in "C"?3Thiago Adams
20 Dec 24 i   i i+- Re: Something like string-streams existing in "C"?1Michael S
20 Dec 24 i   i i`- Re: Something like string-streams existing in "C"?1Lawrence D'Oliveiro
20 Dec 24 i   i `- Re: Something like string-streams existing in "C"?1Keith Thompson
20 Dec 24 i   `- Re: Something like string-streams existing in "C"?1Michael S
20 Dec 24 `- Re: Something like string-streams existing in "C"?1Janis Papanagnou

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal