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


Groups > comp.lang.c > #76056

Re: how to do this?

From Ian Collins <ian-news@hotmail.com>
Newsgroups comp.lang.c
Subject Re: how to do this?
Date 2015-11-15 13:18 +1300
Message-ID <daq19sFi0ttU11@mid.individual.net> (permalink)
References <n2849g$a6p$1@dont-email.me> <dapqp9Fi0ttU9@mid.individual.net> <n28emj$nl3$1@dont-email.me> <n28fpg$rmm$1@dont-email.me> <5647CDEA.8050307@verizon.net>

Show all headers | View raw


James Kuyper wrote:
> On 11/14/2015 06:25 PM, bilsch01 wrote:
>> On 11/14/2015 03:07 PM, bilsch01 wrote:
>>> On 11/14/2015 02:26 PM, Ian Collins wrote:
>>>> bilsch01 wrote:
>>>>
>>>> One I missed earlier:
>>>>
>>>>> char mk1[9] = "**  1  **", mk2[9] = "**  2  **", mk3[9] = "**  3  **";
>>>>
>>>> These aren't null terminated strings.
>>>>
>>>>>
>>>>>              if (strcmp(vec2, vec1) == 0)
>>>>>                      strcpy(vec2, mk1);
>>>>
>>>> So this copy could go horribly wrong.
>>>>
>>> why isn't "**  1  **" a null terminated string?  How should I declare it
>>> to make it null terminated?
>>>
>>> char "**  1  **",0
>>>
>>> I thought when you declare an array of type char it gets null terminated
>>> if "" are used.
>>
>>    Oh.  The vec1 , vec2 . . . aren't null terminated.  I don't see any
>> way to fix that.
>>
>
> This will automatically make mk1 10 bytes long, large enough to include
> the terminating null character:
>
> 	char mk1[] = "**  1  **";

Given what they are and how they are used, a better definition would be:

   const char* mk1 = "**  1  **";

-- 
Ian Collins

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


Thread

how to do this? bilsch01 <king621@comcast.net> - 2015-11-14 12:09 -0800
  Re: how to do this? Rosario19 <Ros@invalid.invalid> - 2015-11-14 21:49 +0100
  Re: how to do this? Ian Collins <ian-news@hotmail.com> - 2015-11-15 10:02 +1300
    Re: how to do this? Ian Collins <ian-news@hotmail.com> - 2015-11-15 10:17 +1300
    Re: how to do this? bilsch01 <king621@comcast.net> - 2015-11-14 15:16 -0800
      Re: how to do this? James Kuyper <jameskuyper@verizon.net> - 2015-11-14 18:24 -0500
        Re: how to do this? bilsch01 <king621@comcast.net> - 2015-11-14 15:30 -0800
          Re: how to do this? Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2015-11-14 19:01 -0500
          Re: how to do this? James Kuyper <jameskuyper@verizon.net> - 2015-11-14 19:07 -0500
  Re: how to do this? Ian Collins <ian-news@hotmail.com> - 2015-11-15 11:26 +1300
    Re: how to do this? bilsch01 <king621@comcast.net> - 2015-11-14 15:07 -0800
      Re: how to do this? James Kuyper <jameskuyper@verizon.net> - 2015-11-14 18:17 -0500
      Re: how to do this? bilsch01 <king621@comcast.net> - 2015-11-14 15:25 -0800
        Re: how to do this? Ian Collins <ian-news@hotmail.com> - 2015-11-15 13:10 +1300
          Re: how to do this? James Kuyper <jameskuyper@verizon.net> - 2015-11-14 19:21 -0500
            Re: how to do this? Ian Collins <ian-news@hotmail.com> - 2015-11-15 13:24 +1300
        Re: how to do this? James Kuyper <jameskuyper@verizon.net> - 2015-11-14 19:12 -0500
          Re: how to do this? Ian Collins <ian-news@hotmail.com> - 2015-11-15 13:18 +1300
            Re: how to do this? James Kuyper <jameskuyper@verizon.net> - 2015-11-14 19:23 -0500
  Re: how to do this? bilsch01 <king621@comcast.net> - 2015-11-14 15:18 -0800

csiph-web