<?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: strtok question again in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/strtok-question-again/m-p/3535083#M701596</link>
    <description>Column is 5, sometimes 6....Doesn't rreally matter, strtok crashes when you put NULL, NULL</description>
    <pubDate>Fri, 29 Apr 2005 14:35:23 GMT</pubDate>
    <dc:creator>etienne_7</dc:creator>
    <dc:date>2005-04-29T14:35:23Z</dc:date>
    <item>
      <title>strtok question again</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/strtok-question-again/m-p/3535078#M701591</link>
      <description>Hello,&lt;BR /&gt;I am trying to parse an ASCII file using strtok. The trouble is some string that I am parsing contain one space and I am trying to get them all at once:&lt;BR /&gt;From the string:&lt;BR /&gt;Hello how are you&lt;BR /&gt;I want the following:&lt;BR /&gt;Hello&lt;BR /&gt;how&lt;BR /&gt;are you&lt;BR /&gt;In 3 different strings........&lt;BR /&gt;So far I am using the following code:&lt;BR /&gt;char* pValue;&lt;BR /&gt;pValue = strtok (pText, " \t");&lt;BR /&gt;i = 0;&lt;BR /&gt;do&lt;BR /&gt;{&lt;BR /&gt;pValue = strtok (NULL, " \t");&lt;BR /&gt;i++;&lt;BR /&gt;} while( (pValue != NULL) &amp;amp;&amp;amp; (i &amp;lt; Column) );&lt;BR /&gt;&lt;BR /&gt;what I get is:&lt;BR /&gt;Hello&lt;BR /&gt;how&lt;BR /&gt;are &lt;BR /&gt;you.....&lt;BR /&gt;In fact, I would like strtok to differ from one space to two spaces....&lt;BR /&gt;getting only 3 strings not 4:&lt;BR /&gt;&lt;BR /&gt;For the string:&lt;BR /&gt;"1234    1235    152153   1 111"&lt;BR /&gt;&lt;BR /&gt;I would like to get only 4 strings:&lt;BR /&gt;"1234"&lt;BR /&gt;"1235"&lt;BR /&gt;"152153"&lt;BR /&gt;"1 111"&lt;BR /&gt;&lt;BR /&gt;and not &lt;BR /&gt;"1"</description>
      <pubDate>Fri, 29 Apr 2005 14:00:34 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/strtok-question-again/m-p/3535078#M701591</guid>
      <dc:creator>etienne_7</dc:creator>
      <dc:date>2005-04-29T14:00:34Z</dc:date>
    </item>
    <item>
      <title>Re: strtok question again</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/strtok-question-again/m-p/3535079#M701592</link>
      <description>Did you see my reply to your other strtok question?&lt;BR /&gt;Did that help?&lt;BR /&gt;&lt;BR /&gt;Looks like you need to modify the loop to the &lt;BR /&gt;following:&lt;BR /&gt;&lt;BR /&gt;do&lt;BR /&gt;{&lt;BR /&gt;if (i &amp;lt; Column-1)&lt;BR /&gt;pValue = strtok (NULL, " \t");&lt;BR /&gt;else&lt;BR /&gt;pValue = strtok (NULL, NULL);&lt;BR /&gt;i++;&lt;BR /&gt;} while( (pValue != NULL) &amp;amp;&amp;amp; (i &amp;lt; Column) );</description>
      <pubDate>Fri, 29 Apr 2005 14:14:53 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/strtok-question-again/m-p/3535079#M701592</guid>
      <dc:creator>Biswajit Tripathy</dc:creator>
      <dc:date>2005-04-29T14:14:53Z</dc:date>
    </item>
    <item>
      <title>Re: strtok question again</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/strtok-question-again/m-p/3535080#M701593</link>
      <description>Ok, I will try and did saw your reply but couldn't answer using the thread....will try this time.&lt;BR /&gt;The issue is that the single space could be anytim in the string, not only at the end.&lt;BR /&gt;</description>
      <pubDate>Fri, 29 Apr 2005 14:19:26 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/strtok-question-again/m-p/3535080#M701593</guid>
      <dc:creator>etienne_7</dc:creator>
      <dc:date>2005-04-29T14:19:26Z</dc:date>
    </item>
    <item>
      <title>Re: strtok question again</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/strtok-question-again/m-p/3535081#M701594</link>
      <description>Run time error while doing that....&lt;BR /&gt;            &lt;BR /&gt;            // scan to correct column&lt;BR /&gt;            char* pValue;&lt;BR /&gt;            pValue = strtok (pText, " \t");&lt;BR /&gt;            i = 0;&lt;BR /&gt;            do&lt;BR /&gt;            {&lt;BR /&gt;                pValue = strtok (NULL, NULL);&lt;BR /&gt;                i++;&lt;BR /&gt;            } while( (pValue != NULL) &amp;amp;&amp;amp; (i &amp;lt; Column) );&lt;BR /&gt;&lt;BR /&gt;This doesn't seem to work...any other idea?</description>
      <pubDate>Fri, 29 Apr 2005 14:24:11 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/strtok-question-again/m-p/3535081#M701594</guid>
      <dc:creator>etienne_7</dc:creator>
      <dc:date>2005-04-29T14:24:11Z</dc:date>
    </item>
    <item>
      <title>Re: strtok question again</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/strtok-question-again/m-p/3535082#M701595</link>
      <description>I don't see the if() condition inside the loop in your&lt;BR /&gt;code as I suggested.&lt;BR /&gt;&lt;BR /&gt;What is the value of Column? &lt;BR /&gt;&lt;BR /&gt;- Biswajit&lt;BR /&gt;</description>
      <pubDate>Fri, 29 Apr 2005 14:30:39 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/strtok-question-again/m-p/3535082#M701595</guid>
      <dc:creator>Biswajit Tripathy</dc:creator>
      <dc:date>2005-04-29T14:30:39Z</dc:date>
    </item>
    <item>
      <title>Re: strtok question again</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/strtok-question-again/m-p/3535083#M701596</link>
      <description>Column is 5, sometimes 6....Doesn't rreally matter, strtok crashes when you put NULL, NULL</description>
      <pubDate>Fri, 29 Apr 2005 14:35:23 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/strtok-question-again/m-p/3535083#M701596</guid>
      <dc:creator>etienne_7</dc:creator>
      <dc:date>2005-04-29T14:35:23Z</dc:date>
    </item>
    <item>
      <title>Re: strtok question again</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/strtok-question-again/m-p/3535084#M701597</link>
      <description>It does not crash on my 11.11 system. Is your string&lt;BR /&gt;NULL terminated?&lt;BR /&gt;&lt;BR /&gt;- Biswajit&lt;BR /&gt;</description>
      <pubDate>Fri, 29 Apr 2005 14:47:27 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/strtok-question-again/m-p/3535084#M701597</guid>
      <dc:creator>Biswajit Tripathy</dc:creator>
      <dc:date>2005-04-29T14:47:27Z</dc:date>
    </item>
    <item>
      <title>Re: strtok question again</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/strtok-question-again/m-p/3535085#M701598</link>
      <description>It crashes before the end of the string, at the first pass.</description>
      <pubDate>Fri, 29 Apr 2005 14:53:04 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/strtok-question-again/m-p/3535085#M701598</guid>
      <dc:creator>etienne_7</dc:creator>
      <dc:date>2005-04-29T14:53:04Z</dc:date>
    </item>
    <item>
      <title>Re: strtok question again</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/strtok-question-again/m-p/3535086#M701599</link>
      <description>Can you post your full program? &lt;BR /&gt;&lt;BR /&gt;- Biswajit&lt;BR /&gt;</description>
      <pubDate>Fri, 29 Apr 2005 14:54:31 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/strtok-question-again/m-p/3535086#M701599</guid>
      <dc:creator>Biswajit Tripathy</dc:creator>
      <dc:date>2005-04-29T14:54:31Z</dc:date>
    </item>
    <item>
      <title>Re: strtok question again</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/strtok-question-again/m-p/3535087#M701600</link>
      <description>include is the function I am using.&lt;BR /&gt;tx</description>
      <pubDate>Fri, 29 Apr 2005 14:59:32 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/strtok-question-again/m-p/3535087#M701600</guid>
      <dc:creator>etienne_7</dc:creator>
      <dc:date>2005-04-29T14:59:32Z</dc:date>
    </item>
    <item>
      <title>Re: strtok question again</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/strtok-question-again/m-p/3535088#M701601</link>
      <description>Here is my code:&lt;BR /&gt;&lt;BR /&gt;#include &lt;STDIO.H&gt;&lt;BR /&gt;#include &lt;STRING.H&gt;&lt;BR /&gt;&lt;BR /&gt;int main ()&lt;BR /&gt;{&lt;BR /&gt;    int i, Column;&lt;BR /&gt;    char pText[512];&lt;BR /&gt;    char *pValue;&lt;BR /&gt;&lt;BR /&gt;    /* Your first string */&lt;BR /&gt;    i = 0;&lt;BR /&gt;    strcpy (pText, "Hello how are you");&lt;BR /&gt;    printf ("----&amp;gt; Your first string = \"%s\"\n", pText);&lt;BR /&gt;    Column = 2; /* Set Column to # of words in string minus 2 */&lt;BR /&gt;    pValue = strtok (pText, " \t");&lt;BR /&gt;    printf ("pValue=\"%s\"\n", pValue);&lt;BR /&gt;    do {&lt;BR /&gt; if (i &amp;lt; Column - 1 )&lt;BR /&gt;            pValue = strtok (NULL, " \t");&lt;BR /&gt;        else&lt;BR /&gt;     pValue = strtok (NULL, "\0");&lt;BR /&gt;        i++;&lt;BR /&gt;        printf ("pValue=\"%s\"\n", pValue);&lt;BR /&gt;    } while( (pValue != NULL) &amp;amp;&amp;amp; (i &amp;lt; Column) );&lt;BR /&gt;&lt;BR /&gt;    /* Your second string */&lt;BR /&gt;&lt;BR /&gt;    i = 0;&lt;BR /&gt;    strcpy (pText, "1234 1235 152153 1 1111");&lt;BR /&gt;    printf ("----&amp;gt; Your Second string = \"%s\"\n", pText);&lt;BR /&gt;    Column = 3; /* Set Column to # of words in string minus 2 */&lt;BR /&gt;    pValue = strtok (pText, " \t");&lt;BR /&gt;    printf ("pValue=\"%s\"\n", pValue);&lt;BR /&gt;    do {&lt;BR /&gt; if (i &amp;lt; Column - 1)&lt;BR /&gt;            pValue = strtok (NULL, " \t");&lt;BR /&gt;        else&lt;BR /&gt;     pValue = strtok (NULL, "\0");&lt;BR /&gt;        printf ("pValue=\"%s\"\n", pValue);&lt;BR /&gt;        i++;&lt;BR /&gt;    } while( (pValue != NULL) &amp;amp;&amp;amp; (i &amp;lt; Column) );&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;    return 0;&lt;BR /&gt;}&lt;BR /&gt;&lt;/STRING.H&gt;&lt;/STDIO.H&gt;</description>
      <pubDate>Fri, 29 Apr 2005 15:08:25 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/strtok-question-again/m-p/3535088#M701601</guid>
      <dc:creator>Biswajit Tripathy</dc:creator>
      <dc:date>2005-04-29T15:08:25Z</dc:date>
    </item>
    <item>
      <title>Re: strtok question again</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/strtok-question-again/m-p/3535089#M701602</link>
      <description>Your code is actually working but I think I was not explicite enough on what I needed, I apologise for that.&lt;BR /&gt;Here is a screen capture of your code working....(see attached)&lt;BR /&gt;&lt;BR /&gt;I want the strtok to differ when there is one space and 2 spaces, when there are 2 space, it is a different word, when it is 1 space it belongs to the same name...&lt;BR /&gt;&lt;BR /&gt;"Hello      how     are you?   good me   too."&lt;BR /&gt;This will become:&lt;BR /&gt;Hello&lt;BR /&gt;how &lt;BR /&gt;are you?&lt;BR /&gt;good me&lt;BR /&gt;too.&lt;BR /&gt;As you can see, when there was more than one space, it considered it as 2 different string but when there was only one space the it put it together.&lt;BR /&gt;Thanks for your help already, I liked it the way you did the first program, looking for the end of string "\0".&lt;BR /&gt;rgds&lt;BR /&gt;</description>
      <pubDate>Mon, 02 May 2005 10:20:28 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/strtok-question-again/m-p/3535089#M701602</guid>
      <dc:creator>etienne_7</dc:creator>
      <dc:date>2005-05-02T10:20:28Z</dc:date>
    </item>
    <item>
      <title>Re: strtok question again</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/strtok-question-again/m-p/3535090#M701603</link>
      <description>etienne wrote:&lt;BR /&gt;&amp;gt; I want the strtok to differ when there is one &lt;BR /&gt;&amp;gt; space and 2 spaces, when there are 2 space, it is&lt;BR /&gt;&amp;gt; a different word, when it is 1 space it belongs to &lt;BR /&gt;&amp;gt; the same name...&lt;BR /&gt;&lt;BR /&gt;To do this, I would probably not use strtok. I would&lt;BR /&gt;use strchr() to search for single space char in a for&lt;BR /&gt;loop and when found, I would print and decide if I&lt;BR /&gt;need to print a space or a newline by looking at the&lt;BR /&gt;next char. Only pass the unprocessed part of the &lt;BR /&gt;input string as the first parameter to strchr().&lt;BR /&gt;&lt;BR /&gt;I'm not loged into a HP-UX machine rightnow, so &lt;BR /&gt;can't give you an example code; but it should be &lt;BR /&gt;quite simple.&lt;BR /&gt;&lt;BR /&gt;- Biswajit&lt;BR /&gt;</description>
      <pubDate>Mon, 02 May 2005 12:48:03 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/strtok-question-again/m-p/3535090#M701603</guid>
      <dc:creator>Biswajit Tripathy</dc:creator>
      <dc:date>2005-05-02T12:48:03Z</dc:date>
    </item>
  </channel>
</rss>

