<?xml version="1.0" encoding="iso-8859-1"?>
<rss version="2.0">
<channel>
  <title>Linux Format forums</title>
  <link>http://www.linuxformat.com/forums/index.php</link>
  <description>Help, discussion, magazine feedback and more</description>
  <language>english</language>
  <copyright>(c) Copyright Sat May 25, 2013 11:14 pm by Linux Format forums</copyright>
  <managingEditor>webmaster@linuxformat.com</managingEditor>
  <webMaster>webmaster@linuxformat.com</webMaster>
  <pubDate>Sat May 25, 2013 11:14 pm</pubDate>
  <lastBuildDate>Sat May 25, 2013 11:14 pm</lastBuildDate>
  <docs>http://backend.userland.com/rss</docs>
  <generator>phpBB2 RSS Syndication Mod by Lucas</generator>
  <ttl>1</ttl>

  <image>
    <title>Linux Format forums</title>
    <url></url>
    <link>http://www.linuxformat.com/forums/</link>
    <description>Help, discussion, magazine feedback and more</description>
  </image>

                                      <item>
                                        <title>RE: data array??</title>
                                        <link>http://www.linuxformat.com/forums/viewtopic.php?p=28375#28375</link>
                                        <description>&lt;br /&gt;
                                      Author: &lt;a href='http://www.linuxformat.com/forums/profile.php?mode=viewprofile&amp;u=5530'&gt;GMorgan&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;
                                      Posted: Fri Jul 28, 2006 9:05 pm&lt;br /&gt;&lt;br /&gt;
                                      &lt;br /&gt;&lt;br /&gt;
                                      Another thing, remember to place the struct definition in the files header rather than inside a function.</description>
                                        <comments>http://www.linuxformat.com/forums/viewtopic.php?p=28375#28375</comments>
                                        <author>GMorgan</author>
                                        <pubDate>Fri Jul 28, 2006 9:05 pm</pubDate>
                                        <guid isPermaLink="true">http://www.linuxformat.com/forums/viewtopic.php?p=28375#28375</guid>
                                      </item>
                                      <item>
                                        <title>RE: data array??</title>
                                        <link>http://www.linuxformat.com/forums/viewtopic.php?p=28304#28304</link>
                                        <description>&lt;br /&gt;
                                      Author: &lt;a href='http://www.linuxformat.com/forums/profile.php?mode=viewprofile&amp;u=127'&gt;alloydog&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;
                                      Posted: Fri Jul 28, 2006 8:08 am&lt;br /&gt;&lt;br /&gt;
                                      &lt;br /&gt;&lt;br /&gt;
                                      Thanks, that's given me somewhere to start from!</description>
                                        <comments>http://www.linuxformat.com/forums/viewtopic.php?p=28304#28304</comments>
                                        <author>alloydog</author>
                                        <pubDate>Fri Jul 28, 2006 8:08 am</pubDate>
                                        <guid isPermaLink="true">http://www.linuxformat.com/forums/viewtopic.php?p=28304#28304</guid>
                                      </item>
                                      <item>
                                        <title>RE: data array??</title>
                                        <link>http://www.linuxformat.com/forums/viewtopic.php?p=28270#28270</link>
                                        <description>&lt;br /&gt;
                                      Author: &lt;a href='http://www.linuxformat.com/forums/profile.php?mode=viewprofile&amp;u=5530'&gt;GMorgan&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;
                                      Posted: Thu Jul 27, 2006 5:36 pm&lt;br /&gt;&lt;br /&gt;
                                      &lt;br /&gt;&lt;br /&gt;
                                      Personally I'd create a struct to account for the weapon. Prehaps something like this.&lt;br /&gt;
&lt;br /&gt;
&lt;/span&gt;&lt;table width=&quot;90%&quot; cellspacing=&quot;1&quot; cellpadding=&quot;3&quot; border=&quot;0&quot; align=&quot;center&quot;&gt;&lt;tr&gt; 	  &lt;td&gt;&lt;span class=&quot;genmed&quot;&gt;&lt;b&gt;Code:&lt;/b&gt;&lt;/span&gt;&lt;/td&gt;	&lt;/tr&gt;	&lt;tr&gt;	  &lt;td class=&quot;code&quot;&gt;typedef struct&amp;#123;&lt;br /&gt;
string name;&lt;br /&gt;
int numhands;&lt;br /&gt;
int weapontype;&lt;br /&gt;
int basedamage;&lt;br /&gt;
&amp;#125;weapon;&lt;br /&gt;
&lt;/td&gt;	&lt;/tr&gt;&lt;/table&gt;&lt;span class=&quot;postbody&quot;&gt;&lt;br /&gt;
&lt;br /&gt;
Here name is obvious, numhands is the handedness of the weapon so obviously 1 and 2 are the correct values. The value weapontype would contain an index for the weapon. So sword may enter 1, mace 2, bow 3 etc. Variable basedamage would give you your lowest damage value.&lt;br /&gt;
&lt;br /&gt;
Just add fields for all the other posibilities then create an array of them. So your array might be created like this.&lt;br /&gt;
&lt;br /&gt;
&lt;/span&gt;&lt;table width=&quot;90%&quot; cellspacing=&quot;1&quot; cellpadding=&quot;3&quot; border=&quot;0&quot; align=&quot;center&quot;&gt;&lt;tr&gt; 	  &lt;td&gt;&lt;span class=&quot;genmed&quot;&gt;&lt;b&gt;Code:&lt;/b&gt;&lt;/span&gt;&lt;/td&gt;	&lt;/tr&gt;	&lt;tr&gt;	  &lt;td class=&quot;code&quot;&gt;&lt;br /&gt;
weapon allweapons&amp;#91;x&amp;#93;;&lt;br /&gt;
&lt;/td&gt;	&lt;/tr&gt;&lt;/table&gt;&lt;span class=&quot;postbody&quot;&gt;&lt;br /&gt;
&lt;br /&gt;
Where x is the number of entries. To access the different fields you use the following.&lt;br /&gt;
&lt;br /&gt;
&lt;/span&gt;&lt;table width=&quot;90%&quot; cellspacing=&quot;1&quot; cellpadding=&quot;3&quot; border=&quot;0&quot; align=&quot;center&quot;&gt;&lt;tr&gt; 	  &lt;td&gt;&lt;span class=&quot;genmed&quot;&gt;&lt;b&gt;Code:&lt;/b&gt;&lt;/span&gt;&lt;/td&gt;	&lt;/tr&gt;	&lt;tr&gt;	  &lt;td class=&quot;code&quot;&gt;&lt;br /&gt;
allweapons&amp;#91;x&amp;#93;.numhands = y;&lt;br /&gt;
&lt;/td&gt;	&lt;/tr&gt;&lt;/table&gt;&lt;span class=&quot;postbody&quot;&gt;&lt;br /&gt;
or&lt;br /&gt;
&lt;/span&gt;&lt;table width=&quot;90%&quot; cellspacing=&quot;1&quot; cellpadding=&quot;3&quot; border=&quot;0&quot; align=&quot;center&quot;&gt;&lt;tr&gt; 	  &lt;td&gt;&lt;span class=&quot;genmed&quot;&gt;&lt;b&gt;Code:&lt;/b&gt;&lt;/span&gt;&lt;/td&gt;	&lt;/tr&gt;	&lt;tr&gt;	  &lt;td class=&quot;code&quot;&gt;&lt;br /&gt;
y = allweapons&amp;#91;x&amp;#93;.numhands;&lt;br /&gt;
&lt;/td&gt;	&lt;/tr&gt;&lt;/table&gt;&lt;span class=&quot;postbody&quot;&gt;&lt;br /&gt;
&lt;br /&gt;
When called like that all the normal operations work on them as they would for the normal datatypes including assignments as LV's and RV's as above or for use in comparisons.&lt;br /&gt;
&lt;br /&gt;
//edit -  a quick tip about arrays. They are indexed from 0 so 0 is the first entry not 1.//</description>
                                        <comments>http://www.linuxformat.com/forums/viewtopic.php?p=28270#28270</comments>
                                        <author>GMorgan</author>
                                        <pubDate>Thu Jul 27, 2006 5:36 pm</pubDate>
                                        <guid isPermaLink="true">http://www.linuxformat.com/forums/viewtopic.php?p=28270#28270</guid>
                                      </item>
                                      <item>
                                        <title>data array??</title>
                                        <link>http://www.linuxformat.com/forums/viewtopic.php?p=28267#28267</link>
                                        <description>&lt;br /&gt;
                                      Author: &lt;a href='http://www.linuxformat.com/forums/profile.php?mode=viewprofile&amp;u=127'&gt;alloydog&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;
                                      Posted: Thu Jul 27, 2006 5:17 pm&lt;br /&gt;&lt;br /&gt;
                                      &lt;br /&gt;&lt;br /&gt;
                                      I'm not a 100% sure if I'm on the right track...&lt;br /&gt;
&lt;br /&gt;
I am going to try and right a programme (for a wargame) that calculates the damage done by a weapon.  The weapon has several 'characterisitics', being:&lt;br /&gt;
• name&lt;br /&gt;
• one- or two-handed&lt;br /&gt;
• number of dice to roll (if one-handed)&lt;br /&gt;
• number of dice to roll (if two-handed)&lt;br /&gt;
• bonus points (if one-handed)&lt;br /&gt;
• bonus points (if two-handed)&lt;br /&gt;
&lt;br /&gt;
Some weapons can be used only two-handed, or only single-handed.  for example:&lt;br /&gt;
&lt;br /&gt;
&lt;/span&gt;&lt;table width=&quot;90%&quot; cellspacing=&quot;1&quot; cellpadding=&quot;3&quot; border=&quot;0&quot; align=&quot;center&quot;&gt;&lt;tr&gt; 	  &lt;td&gt;&lt;span class=&quot;genmed&quot;&gt;&lt;b&gt;Code:&lt;/b&gt;&lt;/span&gt;&lt;/td&gt;	&lt;/tr&gt;	&lt;tr&gt;	  &lt;td class=&quot;code&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ONE-HANDED&amp;nbsp; &amp;nbsp; TWO-HANDED&lt;br /&gt;
TYPE&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;DICE&amp;nbsp; &amp;nbsp;BONUS&amp;nbsp; DICE&amp;nbsp; &amp;nbsp;BONUS&lt;br /&gt;
Broadsword&amp;nbsp; &amp;nbsp; &amp;nbsp; -&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;-&amp;nbsp; &amp;nbsp; &amp;nbsp;5&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2&lt;br /&gt;
Bastardsword&amp;nbsp; &amp;nbsp; 3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2&amp;nbsp; &amp;nbsp; &amp;nbsp;4&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0&lt;br /&gt;
Sword&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0&amp;nbsp; &amp;nbsp; &amp;nbsp;-&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;-&lt;/td&gt;	&lt;/tr&gt;&lt;/table&gt;&lt;span class=&quot;postbody&quot;&gt;&lt;br /&gt;
&lt;br /&gt;
How would I put this information so that a C++ programme could use it?&lt;br /&gt;
&lt;br /&gt;
The aim is for the used just to select the weapon used and the programme returns a value for the damage done.&lt;br /&gt;
&lt;br /&gt;
Is &lt;span style=&quot;font-weight: bold&quot;&gt;&lt;span style=&quot;font-style: italic&quot;&gt;data array&lt;/span&gt; &lt;/span&gt; the correct term?</description>
                                        <comments>http://www.linuxformat.com/forums/viewtopic.php?p=28267#28267</comments>
                                        <author>alloydog</author>
                                        <pubDate>Thu Jul 27, 2006 5:17 pm</pubDate>
                                        <guid isPermaLink="true">http://www.linuxformat.com/forums/viewtopic.php?p=28267#28267</guid>
                                      </item></channel></rss>