Deutsch English Français Italiano |
<vjvsvb$2i07u$1@dont-email.me> View for Bookmarking (what is this?) Look up another Usenet article |
Path: ...!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Janis Papanagnou <janis_papanagnou+ng@hotmail.com> Newsgroups: comp.lang.c Subject: Something like string-streams existing in "C"? Date: Thu, 19 Dec 2024 02:30:18 +0100 Organization: A noiseless patient Spider Lines: 24 Message-ID: <vjvsvb$2i07u$1@dont-email.me> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Injection-Date: Thu, 19 Dec 2024 02:30:20 +0100 (CET) Injection-Info: dont-email.me; posting-host="a63e45c510fdf6ac619df740ab2d96ae"; logging-data="2687230"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18Uqgg5gHMdK7gGAyc8bxZM" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0 Cancel-Lock: sha1:8+tBpoF8pBCakJsO7zsDVqCZoUA= X-Enigmail-Draft-Status: N1110 X-Mozilla-News-Host: news://news.eternal-september.org:119 Bytes: 1907 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