Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c++ > #86568

Re: How do C -programmers do reliable string handling?

From Bo Persson <bo@bo-persson.se>
Newsgroups comp.lang.c++
Subject Re: How do C -programmers do reliable string handling?
Date 2022-09-24 21:00 +0200
Message-ID <jp92f3Ftg4aU1@mid.individual.net> (permalink)
References <tgnedd$31bvi$1@dont-email.me>

Show all headers | View raw


On 2022-09-24 at 19:22, JiiPee wrote:
> I have done C++ since 1997. I personally do not understand why use C if 
> C++ is extented C and has more in it (and thats why I immediately 
> swiched from C to C++ when I found C++).
> 
> But language-fight aside :) .. I have a serious/honest question:
> What is the best way to represend a string in C language? How do best C 
> programmers represend a string?
> 
> Because I am worried that that the length of the string is not 
> "protected" as there is no private in C language.
> 
> In C++ it is well protected and safe something like this:
> 
> class String {
> // all access functions
> 
> private:
> int m_lenght;
> };
> 
> So, it is basically impossible to have a wrong lenght value for a string.
> Am I right that C programmers do it something like:
> 
> struct String {
> char* data;
> int lenght;
> };
> 
> but obviously somebody might put: lenght = 99999999999, and then its 
> going bad....
> 
> How do C programmers make string safe that the above problem does not 
> occur (that the lenght of the string goes wrong)?

By not storing the length separately? You just have to call strlen each 
time you need to know the length.

Back to comp.lang.c++ | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

How do C -programmers do reliable string handling? JiiPee <kerrttuPoistaTama11@gmail.com> - 2022-09-24 20:22 +0300
  Re: How do C -programmers do reliable string handling? Bo Persson <bo@bo-persson.se> - 2022-09-24 21:00 +0200
  Re: How do C -programmers do reliable string handling? Gawr Gura <gawrgura@mail.hololive.com> - 2022-09-24 12:29 -0700
    Re: How do C -programmers do reliable string handling? JiiPee <kerrttuPoistaTama11@gmail.com> - 2022-09-25 00:47 +0300
      Re: How do C -programmers do reliable string handling? Muttley@dastardlyhq.com - 2022-09-25 08:50 +0000
        Re: How do C -programmers do reliable string handling? JiiPee <kerrttuPoistaTama11@gmail.com> - 2022-09-25 13:37 +0300
        Re: How do C -programmers do reliable string handling? JiiPee <kerrttuPoistaTama11@gmail.com> - 2022-09-25 13:38 +0300
        Re: How do C -programmers do reliable string handling? Bonita Montero <Bonita.Montero@gmail.com> - 2022-09-25 13:34 +0200
          Re: How do C -programmers do reliable string handling? Bonita Montero <Bonita.Montero@gmail.com> - 2022-09-25 17:00 +0200
          Re: How do C -programmers do reliable string handling? Muttley@dastardlyhq.com - 2022-09-25 15:14 +0000
      Re: How do C -programmers do reliable string handling? Gawr Gura <gawrgura@mail.hololive.com> - 2022-09-25 09:22 -0700
        Re: How do C -programmers do reliable string handling? JiiPee <kerrttuPoistaTama11@gmail.com> - 2022-09-26 01:01 +0300
          Re: How do C -programmers do reliable string handling? Richard Damon <Richard@Damon-Family.org> - 2022-09-25 19:02 -0400
            Re: How do C -programmers do reliable string handling? JiiPee <kerrttuPoistaTama11@gmail.com> - 2022-09-26 07:27 +0300
              Re: How do C -programmers do reliable string handling? Muttley@dastardlyhq.com - 2022-09-26 15:19 +0000
                Re: How do C -programmers do reliable string handling? JiiPee <kerrttuPoistaTama11@gmail.com> - 2022-09-26 21:53 +0300
                Re: How do C -programmers do reliable string handling? Richard Damon <Richard@Damon-Family.org> - 2022-09-26 20:42 -0400
                Re: How do C -programmers do reliable string handling? Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2022-09-26 17:54 -0700
                Re: How do C -programmers do reliable string handling? Muttley@dastardlyhq.com - 2022-09-27 09:36 +0000
                Re: How do C -programmers do reliable string handling? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2022-09-27 15:28 +0100
          Re: How do C -programmers do reliable string handling? Gawr Gura <gawrgura@mail.hololive.com> - 2022-09-25 16:34 -0700
            Re: How do C -programmers do reliable string handling? JiiPee <kerrttuPoistaTama11@gmail.com> - 2022-09-26 07:32 +0300
    Re: How do C -programmers do reliable string handling? Juha Nieminen <nospam@thanks.invalid> - 2022-09-26 08:33 +0000
      Re: How do C -programmers do reliable string handling? Paavo Helde <eesnimi@osa.pri.ee> - 2022-09-26 12:18 +0300
        Re: How do C -programmers do reliable string handling? Juha Nieminen <nospam@thanks.invalid> - 2022-09-26 09:47 +0000
      Re: How do C -programmers do reliable string handling? Gawr Gura <gawrgura@mail.hololive.com> - 2022-09-26 07:40 -0700
  Re: How do C -programmers do reliable string handling? Paavo Helde <eesnimi@osa.pri.ee> - 2022-09-24 23:04 +0300
    Re: How do C -programmers do reliable string handling? JiiPee <kerrttuPoistaTama11@gmail.com> - 2022-09-25 00:44 +0300
  Re: How do C -programmers do reliable string handling? Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2022-09-26 02:03 -0700

csiph-web