<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: multidimensional code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Thu, 24 Jul 2008 07:31:26 GMT</pubDate>
    <description>DZone Snippets: multidimensional code</description>
    <item>
      <title>Read Multidimensional C char Array of Unknown Length</title>
      <link>http://snippets.dzone.com/posts/show/4034</link>
      <description>Reading a multidimensional C char array (aka C String array) containing char 0 and terminated with literal zero without knowing length.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;char *a[] = { "11", "23", "", "44", "11", "", "16", "36", "", "51", "71", "", "46", "26", "", "14", "68", 0};&lt;br /&gt;int sentinel = 0;&lt;br /&gt;int i = 0;&lt;br /&gt;while ( *(a + i++) != sentinel ) { /* counting away */ }&lt;br /&gt;int aLength = i; // 18, length&lt;br /&gt;int aUbound = i - 1; // 17, index of last element&lt;br /&gt;int aMaxIdx = i - 2; // 16, index of last element where a[i] doesn't cause seg fault&lt;br /&gt;// You now have the lengths so read like normal&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Thu, 17 May 2007 00:56:20 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/4034</guid>
      <author>jokeyxero (xero)</author>
    </item>
  </channel>
</rss>
