Re: Help with string containing null ('\0') chars ...
From: Francis Glassborow (francis_at_robinton.demon.co.uk)
Date: 05/13/04
- Next message: Francis Glassborow: "Re: Initialize data member by using a linitialize list"
- Previous message: Francis Glassborow: "Re: referencing, dereferencing operators"
- In reply to: Surely: "Help with string containing null ('\0') chars ..."
- Next in thread: Surely: "Re: Help with string containing null ('\0') chars ..."
- Reply: Surely: "Re: Help with string containing null ('\0') chars ..."
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Thu, 13 May 2004 10:47:58 +0100
In message <bm45a0lek8j5vn4fqio38icqr10blp9dj2@4ax.com>, Surely
<think@wise.com> writes
>I am trying to checksum an array of characters which is the string:
>
> static char prog_msg[] = { "\0\0\0$1001FFF@80001112131AF7D\r" };
>
>I have tried various kinds of loops to assign each char in the above
>string (prog_msg) to another indexed variable (pkt) needed for the
>CkSm function. Example:
>
>i = 0;
>len = sizeof (prog_msg);
>
>while (i < len)
>
>{
>
>if (prog_msg[i] != '\0') /* if null move past it */
>
> { pkt[i] = prog_msg[i]; } /* otherwise, add it to pkt */
But this does not 'ignore' nulls it replaces them with whatever was
already at that point in pkt which might be anything, including a null.
So what was your intent?
>
>++i; /* then increment counter */
>
>
>}
>
>CkSm(pkt);
>
>The process fails because each of the nulls make the routine think
>that pkt is terminated. Therefore it doesn't progress through to
>the actual end of the string. The result is that pkt has no
>characters to pass off to CkSm. The prog_msg ACTUALLY is part of a
>received message protocol, a remote command from the outside world,
>so I can't just ignore the null's.
>
>How can all of the characters be assigned (including the null's) into
>pkt?
CkSm() needs to be written to handle nulls, which means that it also
must have a second parameter identifying the length of the array being
processed. In simple terms, if you did not write CkSm() then you cannot
use it on arrays of char with embedded nulls.
-- Francis Glassborow ACCU Author of 'You Can Do It!' see http://www.spellen.org/youcandoit For project ideas and contributions: http://www.spellen.org/youcandoit/projects
- Next message: Francis Glassborow: "Re: Initialize data member by using a linitialize list"
- Previous message: Francis Glassborow: "Re: referencing, dereferencing operators"
- In reply to: Surely: "Help with string containing null ('\0') chars ..."
- Next in thread: Surely: "Re: Help with string containing null ('\0') chars ..."
- Reply: Surely: "Re: Help with string containing null ('\0') chars ..."
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|