<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: NULL character assignment not working in C program in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/null-character-assignment-not-working-in-c-program/m-p/4706811#M659799</link>
    <description>I know that a NULL character terminates a string and that a string is an array of characters. I am trying to terminate a string with a NULL character. Why does my program crash when I try to do that?</description>
    <pubDate>Fri, 29 Oct 2010 17:01:54 GMT</pubDate>
    <dc:creator>Curtis Deese</dc:creator>
    <dc:date>2010-10-29T17:01:54Z</dc:date>
    <item>
      <title>NULL character assignment not working in C program</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/null-character-assignment-not-working-in-c-program/m-p/4706809#M659797</link>
      <description>We are using the following version of cc on HP-UX 11.31 Itanium: cc: HP C/aC++ B3910B A.06.25 [Nov 30 2009] &lt;BR /&gt;&lt;BR /&gt;I have the following function:&lt;BR /&gt;&lt;BR /&gt;/*----------trim (char) c from right-side of string *p------------------*/&lt;BR /&gt;char *strtrim_right( char *p)&lt;BR /&gt;{&lt;BR /&gt;    char *end;&lt;BR /&gt;    int len;&lt;BR /&gt;&lt;BR /&gt;    len = strlen( p);&lt;BR /&gt;    while ( *p &amp;amp;&amp;amp; len)&lt;BR /&gt;    {&lt;BR /&gt;        WriteDebug("In strtrim_right 2 p='%s'", p);&lt;BR /&gt;&lt;BR /&gt;        end = p + len-1;&lt;BR /&gt;        WriteDebug("In strtrim_right 2 end='%s'", end);&lt;BR /&gt;&lt;BR /&gt;        if(' ' == *end)&lt;BR /&gt;        {&lt;BR /&gt;            WriteDebug("In strtrim_right 3");&lt;BR /&gt;            p[len-1] = '\0';&lt;BR /&gt;            WriteDebug("In strtrim_right 4");&lt;BR /&gt;        }&lt;BR /&gt;        else&lt;BR /&gt;            break;&lt;BR /&gt;&lt;BR /&gt;        len = strlen( p);&lt;BR /&gt;    }&lt;BR /&gt;    WriteDebug("In strtrim_right 5");&lt;BR /&gt;&lt;BR /&gt;    return( p);&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;Here is the output at the end of the log file:&lt;BR /&gt;&lt;BR /&gt;25481-12:58:41.489-dbg In strtrim_right 2 p='Server Assigned. '&lt;BR /&gt;25481-12:58:41.489-dbg In strtrim_right 2 end=' '&lt;BR /&gt;25481-12:58:41.489-dbg In strtrim_right 3&lt;BR /&gt;&lt;BR /&gt;Notice that it never gets to 'In strtrim_right 4'.&lt;BR /&gt;&lt;BR /&gt;Why is my program terminating at the line p[len-1] = '\0'; ?&lt;BR /&gt;&lt;BR /&gt;It also terminates the same way if I use p[len-1] = NULL;&lt;BR /&gt;&lt;BR /&gt;How do I resolve the problem?</description>
      <pubDate>Fri, 29 Oct 2010 16:07:50 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/null-character-assignment-not-working-in-c-program/m-p/4706809#M659797</guid>
      <dc:creator>Curtis Deese</dc:creator>
      <dc:date>2010-10-29T16:07:50Z</dc:date>
    </item>
    <item>
      <title>Re: NULL character assignment not working in C program</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/null-character-assignment-not-working-in-c-program/m-p/4706810#M659798</link>
      <description>Hi:&lt;BR /&gt;&lt;BR /&gt;When you inject a null byte into your string you are effectively terminating the string.  Strings are arrays of characters that are terminated by a NULL byte.&lt;BR /&gt;&lt;BR /&gt;The 'strlen()' function returns the number of characters in the string argument, not including the terminating null byte.&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Fri, 29 Oct 2010 16:57:28 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/null-character-assignment-not-working-in-c-program/m-p/4706810#M659798</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2010-10-29T16:57:28Z</dc:date>
    </item>
    <item>
      <title>Re: NULL character assignment not working in C program</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/null-character-assignment-not-working-in-c-program/m-p/4706811#M659799</link>
      <description>I know that a NULL character terminates a string and that a string is an array of characters. I am trying to terminate a string with a NULL character. Why does my program crash when I try to do that?</description>
      <pubDate>Fri, 29 Oct 2010 17:01:54 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/null-character-assignment-not-working-in-c-program/m-p/4706811#M659799</guid>
      <dc:creator>Curtis Deese</dc:creator>
      <dc:date>2010-10-29T17:01:54Z</dc:date>
    </item>
    <item>
      <title>Re: NULL character assignment not working in C program</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/null-character-assignment-not-working-in-c-program/m-p/4706812#M659800</link>
      <description>I always terminated my strings with "(char)0".&lt;BR /&gt;&lt;BR /&gt;Main problem, you're not decrementing "len" inside of each loop, so you never rollback in the string enough to find the space character.&lt;BR /&gt;&lt;BR /&gt;You're not decrementing len over each loop, which I'm a bit surprised at, since it's the driver for the while loop.  Also, why fool with *end and with trying to move len around (and then somehow not doing it)? &lt;BR /&gt;&lt;BR /&gt;Anyways, just for giggles, I wrote one, but haven't tested it - feel free to ignore.&lt;BR /&gt;&lt;BR /&gt;char *strtrim_right(char *p)&lt;BR /&gt;{&lt;BR /&gt;  int len = strlen(p);&lt;BR /&gt;&lt;BR /&gt;  while (len)&lt;BR /&gt;  {&lt;BR /&gt;     !(*(p+len)-(char)32)?&lt;BR /&gt;        break:&lt;BR /&gt;        len--;&lt;BR /&gt;  }&lt;BR /&gt;  len&amp;gt;0 ? *(p+len)=(char)0 : 0;&lt;BR /&gt;  return (p);&lt;BR /&gt;}</description>
      <pubDate>Fri, 29 Oct 2010 17:49:47 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/null-character-assignment-not-working-in-c-program/m-p/4706812#M659800</guid>
      <dc:creator>TwoProc</dc:creator>
      <dc:date>2010-10-29T17:49:47Z</dc:date>
    </item>
    <item>
      <title>Re: NULL character assignment not working in C program</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/null-character-assignment-not-working-in-c-program/m-p/4706813#M659801</link>
      <description>&lt;!--!*#--&gt;&amp;gt; I know that a NULL character [...]&lt;BR /&gt;&lt;BR /&gt;We normally refer to a NUL character and a&lt;BR /&gt;NULL pointer.  But I digress.&lt;BR /&gt;&lt;BR /&gt;&amp;gt; [...] Why does my program crash when I try&lt;BR /&gt;&amp;gt; to do that?&lt;BR /&gt;&lt;BR /&gt;We non-psychics can't know why your program&lt;BR /&gt;crashes, because WE CAN'T SEE YOUR PROGRAM.&lt;BR /&gt;All we can see is an unbuildable fragment of&lt;BR /&gt;a program.  If you want good free advice,&lt;BR /&gt;then you should make it easier for your&lt;BR /&gt;advisers to figure out what you're doing.&lt;BR /&gt;&lt;BR /&gt;If I try to make what seems like a plausible&lt;BR /&gt;program out of your program fragment, then I&lt;BR /&gt;can _guess_ what your program may be doing.&lt;BR /&gt;In _my_ program, your function works once,&lt;BR /&gt;and fails once.  Here's what my program does:&lt;BR /&gt;&lt;BR /&gt;alp $ cc wd /list /show = (all, nomess)&lt;BR /&gt;alp $ link wd&lt;BR /&gt;alp $ run wd&lt;BR /&gt;Before (1): &amp;gt;Server Assigned. &amp;lt;&lt;BR /&gt;In strtrim_right 2 p='Server Assigned. '&lt;BR /&gt;In strtrim_right 2 end=' '&lt;BR /&gt;In strtrim_right 3&lt;BR /&gt;In strtrim_right 4&lt;BR /&gt;In strtrim_right 2 p='Server Assigned.'&lt;BR /&gt;In strtrim_right 2 end='.'&lt;BR /&gt;In strtrim_right 5&lt;BR /&gt;After (1):  &amp;gt;Server Assigned.&amp;lt;&lt;BR /&gt;Before (2): &amp;gt;Server Assigned.&amp;lt;&lt;BR /&gt;In strtrim_right 2 p='Server Assigned. '&lt;BR /&gt;In strtrim_right 2 end=' '&lt;BR /&gt;In strtrim_right 3&lt;BR /&gt;%SYSTEM-F-ACCVIO, access violation, reason mask=04, virtual address=000000000001&lt;BR /&gt;01C8, PC=0000000000020158, PS=0000001B&lt;BR /&gt;%TRACE-F-TRACEBACK, symbolic stack dump follows&lt;BR /&gt;  image    module    routine             line      rel PC           abs PC&lt;BR /&gt; wd  WD  strtrim_right                   2256 0000000000000158 0000000000020158&lt;BR /&gt; wd  WD  main                            2276 00000000000002FC 00000000000202FC&lt;BR /&gt; wd  WD  __main                          2270 0000000000000234 0000000000020234&lt;BR /&gt;                                            0 FFFFFFFF8037FCE4 FFFFFFFF8037FCE4&lt;BR /&gt;%TRACE-I-END, end of TRACE stack dump&lt;BR /&gt;&lt;BR /&gt;Line 2256 in the listing is the obvious one:&lt;BR /&gt;&lt;BR /&gt;      3    2256             p[len-1] = '\0';&lt;BR /&gt;&lt;BR /&gt;alp $ help /mess /faci = system ACCVIO&lt;BR /&gt;[...]&lt;BR /&gt;The reason mask is&lt;BR /&gt;a longword whose lowest 5 bits, if set, indicate that the&lt;BR /&gt;instruction caused a length violation (bit 0), referenced the&lt;BR /&gt;process page table (bit 1), attempted a read/modify operation&lt;BR /&gt;(bit 2), was a vector operation on an improperly aligned&lt;BR /&gt;vector element (bit 3), or was a vector instruction reference&lt;BR /&gt;to an I/O space address (bit 4).&lt;BR /&gt;[...]&lt;BR /&gt;&lt;BR /&gt;"reason mask=04" has bit 2 set, which means,&lt;BR /&gt;"attempted a read/modify operation".&lt;BR /&gt;&lt;BR /&gt;My (actual, whole, real) program looks like&lt;BR /&gt;this:&lt;BR /&gt;&lt;BR /&gt;alp $ type wd.c&lt;BR /&gt;#include &lt;STDIO.H&gt;&lt;BR /&gt;#include &lt;STRING.H&gt;&lt;BR /&gt;#include &lt;STDARG.H&gt;&lt;BR /&gt;&lt;BR /&gt;int WriteDebug( char *fmt, ...)&lt;BR /&gt;{&lt;BR /&gt;    va_list ap;&lt;BR /&gt;    int n;&lt;BR /&gt;&lt;BR /&gt;    va_start( ap, fmt);&lt;BR /&gt;    n = vprintf( fmt, ap);&lt;BR /&gt;    n += printf( "\n");&lt;BR /&gt;    return n;&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;/*----------trim (char) c from right-side of string *p------------------*/&lt;BR /&gt;char *strtrim_right( char *p)&lt;BR /&gt;{&lt;BR /&gt;    char *end;&lt;BR /&gt;    int len;&lt;BR /&gt;&lt;BR /&gt;    len = strlen( p);&lt;BR /&gt;    while ( *p &amp;amp;&amp;amp; len)&lt;BR /&gt;    {&lt;BR /&gt;        WriteDebug("In strtrim_right 2 p='%s'", p);&lt;BR /&gt;&lt;BR /&gt;        end = p + len-1;&lt;BR /&gt;        WriteDebug("In strtrim_right 2 end='%s'", end);&lt;BR /&gt;&lt;BR /&gt;        if(' ' == *end)&lt;BR /&gt;        {&lt;BR /&gt;            WriteDebug("In strtrim_right 3");&lt;BR /&gt;            p[len-1] = '\0';&lt;BR /&gt;            WriteDebug("In strtrim_right 4");&lt;BR /&gt;        }&lt;BR /&gt;        else&lt;BR /&gt;            break;&lt;BR /&gt;&lt;BR /&gt;        len = strlen( p);&lt;BR /&gt;    }&lt;BR /&gt;    WriteDebug("In strtrim_right 5");&lt;BR /&gt;&lt;BR /&gt;    return( p);&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;int main ( void)&lt;BR /&gt;{&lt;BR /&gt;&lt;BR /&gt;}&lt;BR /&gt;    char str[] = "Server Assigned. ";&lt;BR /&gt;&lt;BR /&gt;    printf( "Before (1): &amp;gt;%s&amp;lt;\n", str);&lt;BR /&gt;    strtrim_right( str);&lt;BR /&gt;    printf( "After (1):  &amp;gt;%s&amp;lt;\n", str);&lt;BR /&gt;&lt;BR /&gt;    printf( "Before (2): &amp;gt;%s&amp;lt;\n", str);&lt;BR /&gt;    strtrim_right( "Server Assigned. ");&lt;BR /&gt;    printf( "After (2):  &amp;gt;%s&amp;lt;\n", str);&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;In my environment ...&lt;BR /&gt;alp $ cc /version&lt;BR /&gt;HP C V7.3-009 on OpenVMS Alpha V8.3&lt;BR /&gt;... I get a friendly error message with a&lt;BR /&gt;traceback.  Yours is less convenient, but I&lt;BR /&gt;suspect that the problem there is the same as&lt;BR /&gt;the problem here.  Did you get a "core" file?&lt;BR /&gt;Have you learned how to use a debugger with a&lt;BR /&gt;core file?  It's a good skill to have on a&lt;BR /&gt;UNIX(-like) system.&lt;/STDARG.H&gt;&lt;/STRING.H&gt;&lt;/STDIO.H&gt;</description>
      <pubDate>Fri, 29 Oct 2010 18:00:25 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/null-character-assignment-not-working-in-c-program/m-p/4706813#M659801</guid>
      <dc:creator>Steven Schweda</dc:creator>
      <dc:date>2010-10-29T18:00:25Z</dc:date>
    </item>
    <item>
      <title>Re: NULL character assignment not working in C program</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/null-character-assignment-not-working-in-c-program/m-p/4706814#M659802</link>
      <description>&lt;!--!*#--&gt;&amp;gt; Main problem, [...]&lt;BR /&gt;&lt;BR /&gt;Not really.  (On many levels.)&lt;BR /&gt;&lt;BR /&gt;&amp;gt; You're not decrementing len [...]&lt;BR /&gt;&lt;BR /&gt;      len = strlen( p);&lt;BR /&gt;&lt;BR /&gt;(The second one.)&lt;BR /&gt;&lt;BR /&gt;As usual, it's easier to explore an actual&lt;BR /&gt;program than it is a listing of a program&lt;BR /&gt;fragment.  In fact, while probably not&lt;BR /&gt;ideally efficient, this thing does handle&lt;BR /&gt;multiple trailing spaces.  For example:&lt;BR /&gt;&lt;BR /&gt;alp $ run wd2&lt;BR /&gt;Before (1): &amp;gt;Server Assigned.   &amp;lt;&lt;BR /&gt;In strtrim_right 2 p='Server Assigned.   '&lt;BR /&gt;In strtrim_right 2 end=' '&lt;BR /&gt;In strtrim_right 3&lt;BR /&gt;In strtrim_right 4&lt;BR /&gt;In strtrim_right 2 p='Server Assigned.  '&lt;BR /&gt;In strtrim_right 2 end=' '&lt;BR /&gt;In strtrim_right 3&lt;BR /&gt;In strtrim_right 4&lt;BR /&gt;In strtrim_right 2 p='Server Assigned. '&lt;BR /&gt;In strtrim_right 2 end=' '&lt;BR /&gt;In strtrim_right 3&lt;BR /&gt;In strtrim_right 4&lt;BR /&gt;In strtrim_right 2 p='Server Assigned.'&lt;BR /&gt;In strtrim_right 2 end='.'&lt;BR /&gt;In strtrim_right 5&lt;BR /&gt;After (1):  &amp;gt;Server Assigned.&amp;lt;&lt;BR /&gt;&lt;BR /&gt;What it can _not_ handle is a read-only&lt;BR /&gt;string argument.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&amp;gt; [...] (char)32&lt;BR /&gt;&lt;BR /&gt;Not much on portable code are we?  ASCII is&lt;BR /&gt;not the whole world.  "' '" was better.&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://en.wikipedia.org/wiki/Extended_Binary_Coded_Decimal_Interchange_Code" target="_blank"&gt;http://en.wikipedia.org/wiki/Extended_Binary_Coded_Decimal_Interchange_Code&lt;/A&gt;</description>
      <pubDate>Fri, 29 Oct 2010 18:17:50 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/null-character-assignment-not-working-in-c-program/m-p/4706814#M659802</guid>
      <dc:creator>Steven Schweda</dc:creator>
      <dc:date>2010-10-29T18:17:50Z</dc:date>
    </item>
    <item>
      <title>Re: NULL character assignment not working in C program</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/null-character-assignment-not-working-in-c-program/m-p/4706815#M659803</link>
      <description>&lt;!--!*#--&gt;Less stupid main program:&lt;BR /&gt;&lt;BR /&gt;int main( void)&lt;BR /&gt;{&lt;BR /&gt;    char str1[] = "Server Assigned. ";&lt;BR /&gt;    char *str2 = "Server Assigned. ";&lt;BR /&gt;&lt;BR /&gt;    printf( "Before (1): &amp;gt;%s&amp;lt;\n", str1);&lt;BR /&gt;    strtrim_right( str1);&lt;BR /&gt;    printf( "After (1):  &amp;gt;%s&amp;lt;\n", str1);&lt;BR /&gt;&lt;BR /&gt;    printf( "Before (2): &amp;gt;%s&amp;lt;\n", str2);&lt;BR /&gt;    strtrim_right( str2);&lt;BR /&gt;    printf( "After (2):  &amp;gt;%s&amp;lt;\n", str2);&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;(Essentially the same results, just better&lt;BR /&gt;clarity and diagnostic messages.)&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&amp;gt; [...] I wrote one, [...]&lt;BR /&gt;&lt;BR /&gt;I don't really like code this compact --&lt;BR /&gt;too hard to add in those printf's -- but it's&lt;BR /&gt;an exercise.&lt;BR /&gt;&lt;BR /&gt;char *strtrim_right( char *p)&lt;BR /&gt;{&lt;BR /&gt;    int len;&lt;BR /&gt;&lt;BR /&gt;    for (len = strlen( p);&lt;BR /&gt;     (len &amp;gt; 0) &amp;amp;&amp;amp; (*(p+ (--len)) == ' ');&lt;BR /&gt;     *(p+ len) = '\0');&lt;BR /&gt;&lt;BR /&gt;    return p;&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;Or, if you prefer subscripts to pointer&lt;BR /&gt;dereferencing:&lt;BR /&gt;&lt;BR /&gt;    for (len = strlen( p);&lt;BR /&gt;     (len &amp;gt; 0) &amp;amp;&amp;amp; (p[ --len] == ' ');&lt;BR /&gt;     p[ len] = '\0');&lt;BR /&gt;&lt;BR /&gt;As usual, many things are possible.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&amp;gt; [...] haven't tested it [...]&lt;BR /&gt;&lt;BR /&gt;Testing, of course, is easier with a whole,&lt;BR /&gt;working program.</description>
      <pubDate>Fri, 29 Oct 2010 21:32:45 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/null-character-assignment-not-working-in-c-program/m-p/4706815#M659803</guid>
      <dc:creator>Steven Schweda</dc:creator>
      <dc:date>2010-10-29T21:32:45Z</dc:date>
    </item>
    <item>
      <title>Re: NULL character assignment not working in C program</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/null-character-assignment-not-working-in-c-program/m-p/4706816#M659804</link>
      <description>&amp;gt;Steven: What it can _not_ handle is a read-only string argument.&lt;BR /&gt;char str1[] = "Server Assigned. ";&lt;BR /&gt;char *str2 = "Server Assigned. ";&lt;BR /&gt;&lt;BR /&gt;Right.  The first will work and the second abort (using the default options for +Olit=).</description>
      <pubDate>Sat, 30 Oct 2010 00:40:28 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/null-character-assignment-not-working-in-c-program/m-p/4706816#M659804</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2010-10-30T00:40:28Z</dc:date>
    </item>
    <item>
      <title>Re: NULL character assignment not working in C program</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/null-character-assignment-not-working-in-c-program/m-p/4706817#M659805</link>
      <description>IMHO best one is Steven's below as the cleanest:&lt;BR /&gt;&lt;BR /&gt;    for (len = strlen( p);&lt;BR /&gt;     (len &amp;gt; 0) &amp;amp;&amp;amp; (p[ --len] == ' ');&lt;BR /&gt;     p[ len] = '\0');&lt;BR /&gt;</description>
      <pubDate>Mon, 01 Nov 2010 14:41:01 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/null-character-assignment-not-working-in-c-program/m-p/4706817#M659805</guid>
      <dc:creator>TwoProc</dc:creator>
      <dc:date>2010-11-01T14:41:01Z</dc:date>
    </item>
    <item>
      <title>Re: NULL character assignment not working in C program</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/null-character-assignment-not-working-in-c-program/m-p/4706818#M659806</link>
      <description>&lt;!--!*#--&gt;&amp;gt; IMHO best one is [...]&lt;BR /&gt;&lt;BR /&gt;"best" is not well-defined here.  Note that&lt;BR /&gt;that "for" loop stores a NUL over every&lt;BR /&gt;trailing space character, not only the&lt;BR /&gt;left-most one, so, while the code may be&lt;BR /&gt;compact, it may run more slowly than smarter&lt;BR /&gt;code which stores only the one required NUL&lt;BR /&gt;(in the right place).  And, the speed of any&lt;BR /&gt;such code may depend on the input data --&lt;BR /&gt;more or fewer trailing spaces.  Everything's&lt;BR /&gt;complicated.</description>
      <pubDate>Mon, 01 Nov 2010 17:42:54 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/null-character-assignment-not-working-in-c-program/m-p/4706818#M659806</guid>
      <dc:creator>Steven Schweda</dc:creator>
      <dc:date>2010-11-01T17:42:54Z</dc:date>
    </item>
    <item>
      <title>Re: NULL character assignment not working in C program</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/null-character-assignment-not-working-in-c-program/m-p/4706819#M659807</link>
      <description>Right, so I commented on which code frag I liked, and that one was it.&lt;BR /&gt;&lt;BR /&gt;Reason: It was very small, very tight, yet easy to read. I'd gladly take the extra stores to memory for all of the stack loads and pops for all the subbys in the other extremum of code demonstrated.  Also with your code, I'd bet that the optimizer would stick and run those values out of a register for that code segment regardless, so I don't think it would hurt at all.&lt;BR /&gt;&lt;BR /&gt;I liked the code I posted myself for being quick, small and tight, but I didn't like it all for readability.  &lt;BR /&gt;&lt;BR /&gt;Your code was a much nicer mix of both (tight yet readable).&lt;BR /&gt;&lt;BR /&gt;You **could** have left off the "Less stupid main program" comment at the beginning, just in case you wanted to let folks mistakenly think you're a nice guy for a minute or two, but your code response was very good nonetheless. :-)</description>
      <pubDate>Mon, 01 Nov 2010 18:39:35 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/null-character-assignment-not-working-in-c-program/m-p/4706819#M659807</guid>
      <dc:creator>TwoProc</dc:creator>
      <dc:date>2010-11-01T18:39:35Z</dc:date>
    </item>
    <item>
      <title>Re: NULL character assignment not working in C program</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/null-character-assignment-not-working-in-c-program/m-p/4706820#M659808</link>
      <description>&lt;!--!*#--&gt;&amp;gt; You **could** have left off the "Less&lt;BR /&gt;&amp;gt; stupid main program" comment [...]&lt;BR /&gt;&lt;BR /&gt;I could have, but it seemed to me to be&lt;BR /&gt;appropriate.  It referred to my own original&lt;BR /&gt;main program.  If anyone else supplied one,&lt;BR /&gt;then I missed it.  The copy+paste/typo&lt;BR /&gt;problem in my original main program (spurious&lt;BR /&gt;"}") was not its only defect.  I'm sure that&lt;BR /&gt;if the ITRC Thought Police determine that I'm&lt;BR /&gt;guilty of inflicting personal abuse on&lt;BR /&gt;myself, then they'll take appropriate action.</description>
      <pubDate>Mon, 01 Nov 2010 22:04:12 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/null-character-assignment-not-working-in-c-program/m-p/4706820#M659808</guid>
      <dc:creator>Steven Schweda</dc:creator>
      <dc:date>2010-11-01T22:04:12Z</dc:date>
    </item>
    <item>
      <title>Re: NULL character assignment not working in C program</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/null-character-assignment-not-working-in-c-program/m-p/4706821#M659809</link>
      <description>&amp;gt; TwoProc: I'd gladly take the extra stores to memory for all of the stack loads and pops&lt;BR /&gt;&lt;BR /&gt;There is no stack machine here, RISC and EPIC are register machines.&lt;BR /&gt;&lt;BR /&gt;&amp;gt;I'd bet that the optimizer would stick and run those values out of a register for that code segment regardless, so I don't think it would hurt at all.&lt;BR /&gt;&lt;BR /&gt;You have too much faith in the optimizer.  ;-) You told it to do a store to that pointer, it doesn't know strings are special or that it even is a string.</description>
      <pubDate>Tue, 02 Nov 2010 10:44:52 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/null-character-assignment-not-working-in-c-program/m-p/4706821#M659809</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2010-11-02T10:44:52Z</dc:date>
    </item>
    <item>
      <title>Re: NULL character assignment not working in C program</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/null-character-assignment-not-working-in-c-program/m-p/4706822#M659810</link>
      <description>Dennis - Are you sure? &lt;BR /&gt;&lt;BR /&gt;I know RISC design has lots o' registers so that the compiler optimizer can stick as much stuff as possible in registers.  But, no stack?&lt;BR /&gt;&lt;BR /&gt;And I know that the "no stack" theory has been part of RISC design for a long time, but in truth, there certainly are stacks, and the little tight code that Steven submitted almost absolutely avoids the necessity of using them.&lt;BR /&gt;&lt;BR /&gt;I don't believe that there's a decent way to put together a C compiler that doesn't use a stack, unless we just rule out regression as method of programming, or we stop programs when the registers fill up.&lt;BR /&gt;&lt;BR /&gt;$&amp;gt; kctune | grep maxssiz&lt;BR /&gt;&lt;BR /&gt;for a good look.</description>
      <pubDate>Wed, 03 Nov 2010 20:20:26 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/null-character-assignment-not-working-in-c-program/m-p/4706822#M659810</guid>
      <dc:creator>TwoProc</dc:creator>
      <dc:date>2010-11-03T20:20:26Z</dc:date>
    </item>
    <item>
      <title>Re: NULL character assignment not working in C program</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/null-character-assignment-not-working-in-c-program/m-p/4706823#M659811</link>
      <description>&amp;gt;Are you sure?&lt;BR /&gt;&amp;gt;no stack?&lt;BR /&gt;&lt;BR /&gt;Yes.  I said "stack machine", not no stack.  The stack is simulated on register machines.&lt;BR /&gt;&lt;BR /&gt;&amp;gt;there certainly are stacks, and the little tight code that Steven submitted almost absolutely avoids the necessity of using them.&lt;BR /&gt;&lt;BR /&gt;The compiler cares about sequences of frames, not really stacks.  Steven's code only stores through that pointer p in strtrim_right.  There is no local frame, only a RSE frame on Integrity.&lt;BR /&gt;&lt;BR /&gt;&amp;gt;unless we just rule out regression as method of programming&lt;BR /&gt;&lt;BR /&gt;You mean recursion.&lt;BR /&gt;&lt;BR /&gt;$&amp;gt; kctune maxssiz # for a good look.&lt;BR /&gt;&lt;BR /&gt;This is that simulated stack.</description>
      <pubDate>Thu, 04 Nov 2010 08:22:45 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/null-character-assignment-not-working-in-c-program/m-p/4706823#M659811</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2010-11-04T08:22:45Z</dc:date>
    </item>
    <item>
      <title>Re: NULL character assignment not working in C program</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/null-character-assignment-not-working-in-c-program/m-p/4706824#M659812</link>
      <description>&amp;gt;Are you sure?&lt;BR /&gt;&amp;gt;no stack?&lt;BR /&gt;&lt;BR /&gt;Yes. I said "stack machine", not no stack. The stack is simulated on register machines.&lt;BR /&gt;&lt;BR /&gt;Yep, I just read up on this.  Withdrawn.  It's definitely there as you say.&lt;BR /&gt;&lt;BR /&gt;&amp;gt;there certainly are stacks, and the little tight code that Steven submitted almost absolutely avoids the necessity of using them.&lt;BR /&gt;&lt;BR /&gt;The compiler cares about sequences of frames, not really stacks. Steven's code only stores through that pointer p in strtrim_right. There is no local frame, only a RSE frame on Integrity.&lt;BR /&gt;&lt;BR /&gt;&amp;gt; yep, we've agreed on the fact that Steven's code is not gonna use the stack three or four time snow.&lt;BR /&gt;&lt;BR /&gt;&amp;gt;unless we just rule out regression as method of programming&lt;BR /&gt;&lt;BR /&gt;You mean recursion.&lt;BR /&gt;&lt;BR /&gt;Yep, goofball moment - recursion.&lt;BR /&gt;&lt;BR /&gt;$&amp;gt; kctune maxssiz # for a good look.&lt;BR /&gt;&lt;BR /&gt;This is that simulated stack.&lt;BR /&gt;&lt;BR /&gt;Ok, this point, I need to read up on more.  But I think I see what you're saying in that whole frames (holding a stack) get moved in and out and then the whole thing is processed locally in the stack register machine segment of the cpu.  And then possibly parked back later.  Thanks for the correction.</description>
      <pubDate>Thu, 04 Nov 2010 17:06:24 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/null-character-assignment-not-working-in-c-program/m-p/4706824#M659812</guid>
      <dc:creator>TwoProc</dc:creator>
      <dc:date>2010-11-04T17:06:24Z</dc:date>
    </item>
    <item>
      <title>Re: NULL character assignment not working in C program</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/null-character-assignment-not-working-in-c-program/m-p/4706825#M659813</link>
      <description>&amp;gt;But I think I see what you're saying in that whole frames (holding a stack) get moved in and out and then the whole thing is processed locally in the stack register machine segment of the CPU. And then possibly parked back later.&lt;BR /&gt;&lt;BR /&gt;Possibly you are reading more into the Register Save Engine?&lt;BR /&gt;&lt;BR /&gt;Basically there are two "stacks".  One is for the user data and one is for the register frames.  The RSE automatically spills and fills based on the size of the register frame, on call entry and exits.</description>
      <pubDate>Fri, 05 Nov 2010 04:12:49 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/null-character-assignment-not-working-in-c-program/m-p/4706825#M659813</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2010-11-05T04:12:49Z</dc:date>
    </item>
    <item>
      <title>Re: NULL character assignment not working in C program</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/null-character-assignment-not-working-in-c-program/m-p/4706826#M659814</link>
      <description>Just for fun and addition misers&lt;BR /&gt;char *strtrim_right( char *p)&lt;BR /&gt;{&lt;BR /&gt;    register char *q;&lt;BR /&gt;&lt;BR /&gt;    for (q = p+ strlen( p);&lt;BR /&gt;     (q!=p) &amp;amp;&amp;amp; *(--q) == ' ');&lt;BR /&gt;     *(q) = '\0');&lt;BR /&gt;&lt;BR /&gt;    return p;&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;or to avoid the *(q)=0 on every steps&lt;BR /&gt;and have a move reg to reg in place of a store one char.&lt;BR /&gt;char *strtrim_right( char *p)&lt;BR /&gt;{&lt;BR /&gt;    register char *q,*z;&lt;BR /&gt;&lt;BR /&gt;    for (z = q = p+ strlen( p);&lt;BR /&gt;     (q!=p) &amp;amp;&amp;amp; *(--q) == ' ');&lt;BR /&gt;     z=q);&lt;BR /&gt;     *(z) = '\0');&lt;BR /&gt;&lt;BR /&gt;    return p;&lt;BR /&gt;}</description>
      <pubDate>Sat, 06 Nov 2010 07:59:18 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/null-character-assignment-not-working-in-c-program/m-p/4706826#M659814</guid>
      <dc:creator>Laurent Menase</dc:creator>
      <dc:date>2010-11-06T07:59:18Z</dc:date>
    </item>
    <item>
      <title>Re: NULL character assignment not working in C program</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/null-character-assignment-not-working-in-c-program/m-p/4706827#M659815</link>
      <description>&amp;gt;Laurent: Just for fun and addition misers&lt;BR /&gt;&lt;BR /&gt;You violated the law of conservation of parenthesis and anti-parenthesis.  :-)</description>
      <pubDate>Sat, 06 Nov 2010 10:48:21 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/null-character-assignment-not-working-in-c-program/m-p/4706827#M659815</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2010-11-06T10:48:21Z</dc:date>
    </item>
    <item>
      <title>Re: NULL character assignment not working in C program</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/null-character-assignment-not-working-in-c-program/m-p/4706828#M659816</link>
      <description>Yes Denis, you are right, being miser I wasted parenthesis:&lt;BR /&gt;it is&lt;BR /&gt;char *strtrim_right( char *p)&lt;BR /&gt;{&lt;BR /&gt;register char *q;&lt;BR /&gt;&lt;BR /&gt;for (q = p+ strlen( p);&lt;BR /&gt;(q!=p) &amp;amp;&amp;amp; (*--q == ' ');&lt;BR /&gt;*q = '\0');&lt;BR /&gt;&lt;BR /&gt;return p;&lt;BR /&gt;}&lt;BR /&gt; or &lt;BR /&gt;char *strtrim_right( char *p)&lt;BR /&gt;{&lt;BR /&gt;register char *q,*z;&lt;BR /&gt;&lt;BR /&gt;for (z = q = p+ strlen( p);&lt;BR /&gt;(q!=p) &amp;amp;&amp;amp; ( *--q == ' ');&lt;BR /&gt;z=q);&lt;BR /&gt;*z = '\0';&lt;BR /&gt;&lt;BR /&gt;return p;&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;or now with only one walk from left to right:&lt;BR /&gt;char *strtrim_right( char *p)&lt;BR /&gt;{&lt;BR /&gt;register char *q,*z;&lt;BR /&gt;register char c;&lt;BR /&gt;for (z=0,q=p ;(c=*q);q++)&lt;BR /&gt;{&lt;BR /&gt;   for(;(c=*q)&amp;amp;&amp;amp;(c!=' ');q++);&lt;BR /&gt;   for(z=q;(c=*q)&amp;amp;&amp;amp;(c==' ');q++);&lt;BR /&gt;}&lt;BR /&gt;*z = '\0';&lt;BR /&gt;return p;&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 09 Nov 2010 11:00:50 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/null-character-assignment-not-working-in-c-program/m-p/4706828#M659816</guid>
      <dc:creator>Laurent Menase</dc:creator>
      <dc:date>2010-11-09T11:00:50Z</dc:date>
    </item>
  </channel>
</rss>

