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


Groups > comp.os.os2.programmer.misc > #1613

Re: C: How to convert a \0 char into a dot for printf output?

Path csiph.com!feeder.erje.net!1.eu.feeder.erje.net!weretis.net!feeder4.news.weretis.net!feeder5.news.weretis.net!news.solani.org!.POSTED!not-for-mail
From Lars Erdmann <lars.erdmann@arcor.de>
Newsgroups comp.os.os2.programmer.misc
Subject Re: C: How to convert a \0 char into a dot for printf output?
Date Fri, 18 May 2018 21:29:34 +0200
Organization solani.org
Lines 42
Message-ID <pdn9j2$ff9$1@solani.org> (permalink)
References <pdmv2q$uo1$1@news.albasani.net> <rs6dnUv6aIFYkWLHnZ2dnUU7-dGdnZ2d@giganews.com> <pdn2s2$9hh$1@news.albasani.net>
Mime-Version 1.0
Content-Type text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding 7bit
X-Trace solani.org 1526671778 15849 eJwFwYkBgDAIA8CVCiSpjoM8+4/gHUOmuhAFLvcARslVzAf3HcC/GK8+seuSwXq2FBPp2T8APhDG (18 May 2018 19:29:38 GMT)
X-Complaints-To abuse@news.solani.org
NNTP-Posting-Date Fri, 18 May 2018 19:29:38 +0000 (UTC)
User-Agent Mozilla/5.0 (OS/2; Warp 4.5; rv:45.0) Gecko/20100101 Thunderbird/45.8.0
X-NNTP-Posting-Host eJwFwYERACEIA7CVfGpbGEf02H+ETwh9ut6iNodTNZ32WV5ix8gT6AKFiING8h2+usZVmj8KlhBb
In-Reply-To <pdn2s2$9hh$1@news.albasani.net>
X-User-ID eJwFwYEBwDAEBMCVCI+M46P2H6F3sNB46YFwLNalHj+pEbk3a7y4Y4FcFeTpbaHxHc7GaPMHF/IRhg==
Cancel-Lock sha1:jVT5/RF/1Z4SLYIqBTIK10lbyGk=
Xref csiph.com comp.os.os2.programmer.misc:1613

Show key headers only | View raw


On 18.05.18 19.34, Andreas Schnellbacher wrote:
> On 18.05.18 19:26, James Moe wrote:
>
>> On 05/18/2018 09:30 AM, Andreas Schnellbacher wrote:
>>
>>> I've tried to write a function that should convert each zero char into a
>>> dot. The following function doesn't work and I don't know why.
>>
>> It is because you are removing the string terminator.
>> You need to add a terminator to each string where you replace the
>> terminator so that downstream string processing works as expected.
>
> Thanks. I see, that makes sense. Sure, that's why in another function
> double-zero-terminated strings exist.
>
That's not really true. In C, if you define a string like

"String1\0String2\0"
then in fact, the C compiler will create a string that adds an 
additional zero terminator after this string. Just as it does for any 
string.
What you really need to do is check for the DOUBLE occurrence of a zero 
terminator in order to find the end of the string. Something like this 
(untested):

static PSZ _zerotodot( PSZ pszString)
{
          PSZ            p = pszString;

    if (p != NULL)
       {
       while ((*p != 0) || (*(p+1) != 0)) // !a || !b == !(a && b)
          {
          if (*p == 0)
             *p = '.';
          p++;
          }
          *p = '.';  // treat the very last "visible" zero terminator
       }

    return pszString; // you want to return the conv. string, don't you ?
}

Back to comp.os.os2.programmer.misc | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

C: How to convert a \0 char into a dot for printf output? Andreas Schnellbacher <aschn@despammed.com> - 2018-05-18 18:30 +0200
  Re: C: How to convert a \0 char into a dot for printf output? James Moe <jimoeDESPAM@sohnen-moe.com> - 2018-05-18 10:26 -0700
    Re: C: How to convert a \0 char into a dot for printf output? Andreas Schnellbacher <aschn@despammed.com> - 2018-05-18 19:34 +0200
      Re: C: How to convert a \0 char into a dot for printf output? Lars Erdmann <lars.erdmann@arcor.de> - 2018-05-18 21:29 +0200
        Re: C: How to convert a \0 char into a dot for printf output? Andreas Schnellbacher <aschn@despammed.com> - 2018-05-19 14:29 +0200
          Re: C: How to convert a \0 char into a dot for printf output? Andreas Schnellbacher <aschn@despammed.com> - 2018-05-19 15:30 +0200
            Re: C: How to convert a \0 char into a dot for printf output? "Steven Levine" <steve53@nomail.earthlink.net> - 2018-05-19 09:43 -0500
              Re: C: How to convert a \0 char into a dot for printf output? Andreas Schnellbacher <aschn@despammed.com> - 2018-05-19 18:11 +0200
                Re: C: How to convert a \0 char into a dot for printf output? Andreas Schnellbacher <aschn@despammed.com> - 2018-05-20 13:37 +0200
                Re: C: How to convert a \0 char into a dot for printf output? Peter Flass <peter_flass@yahoo.com> - 2018-05-20 10:36 -0400
                Re: C: How to convert a \0 char into a dot for printf output? "Steven Levine" <steve53@nomail.earthlink.net> - 2018-05-20 10:49 -0500
                Re: C: How to convert a \0 char into a dot for printf output? Andreas Schnellbacher <aschn@despammed.com> - 2018-05-20 18:46 +0200
                Re: C: How to convert a \0 char into a dot for printf output? "Steven Levine" <steve53@nomail.earthlink.net> - 2018-05-21 09:42 -0500
                Re: C: How to convert a \0 char into a dot for printf output? Andreas Schnellbacher <aschn@despammed.com> - 2018-05-21 18:37 +0200
                Re: C: How to convert a \0 char into a dot for printf output? nospam_2018@efbe.prima.de - 2018-05-20 19:06 +0200
                Re: C: How to convert a \0 char into a dot for printf output? Andreas Schnellbacher <aschn@despammed.com> - 2018-05-20 23:30 +0200
                Re: C: How to convert a \0 char into a dot for printf output? Peter Flass <peter_flass@yahoo.com> - 2018-05-20 18:03 -0400
                Re: C: How to convert a \0 char into a dot for printf output? Lars Erdmann <lars.erdmann@arcor.de> - 2018-05-21 09:07 +0200
                Re: C: How to convert a \0 char into a dot for printf output? Andreas Schnellbacher <aschn@despammed.com> - 2018-05-21 11:30 +0200
                Re: C: How to convert a \0 char into a dot for printf output? "Steven Levine" <steve53@nomail.earthlink.net> - 2018-05-21 10:01 -0500
                Re: C: How to convert a \0 char into a dot for printf output? Andreas Schnellbacher <aschn@despammed.com> - 2018-05-21 18:41 +0200
                Re: C: How to convert a \0 char into a dot for printf output? nospam_2018@efbe.prima.de - 2018-05-21 22:56 +0200
                Re: C: How to convert a \0 char into a dot for printf output? "Steven Levine" <steve53@nomail.earthlink.net> - 2018-05-22 10:00 -0500
                Re: C: How to convert a \0 char into a dot for printf output? Andreas Schnellbacher <aschn@despammed.com> - 2018-05-22 21:37 +0200
                Re: C: How to convert a \0 char into a dot for printf output? Andreas Schnellbacher <aschn@despammed.com> - 2018-05-22 21:41 +0200
                Re: C: How to convert a \0 char into a dot for printf output? Andreas Schnellbacher <aschn@despammed.com> - 2018-05-23 23:56 +0200
                Re: C: How to convert a \0 char into a dot for printf output? nospam_2018@efbe.prima.de - 2018-05-22 21:44 +0200
          Re: C: How to convert a \0 char into a dot for printf output? Peter Flass <peter_flass@yahoo.com> - 2018-05-19 11:42 -0400
            Re: C: How to convert a \0 char into a dot for printf output? Andreas Schnellbacher <aschn@despammed.com> - 2018-05-19 18:13 +0200
  Re: C: How to convert a \0 char into a dot for printf output? Andreas Kohl <ak120@arcor.de> - 2018-05-21 09:05 +0200
    Re: C: How to convert a \0 char into a dot for printf output? Andreas Schnellbacher <aschn@despammed.com> - 2018-05-21 11:35 +0200

csiph-web