    <rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:admin="http://webns.net/mvcb/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:content="http://purl.org/rss/1.0/modules/content/">
     <channel>
        <title>ACCU  :: Questions &amp; Answers</title>
        <link>https://members.accu.org/index.php/articles/872</link>
        <description>Professionalism in Programming</description>
        <dc:language>en-us</dc:language> 
        <dc:creator>Administrator</dc:creator> 
        <admin:generatorAgent rdf:resource="http://www.xaraya.org" /> 
        <admin:errorReportsTo rdf:resource="mailto:webeditor@accu.org" />
       <sy:updatePeriod>hourly</sy:updatePeriod>
       <sy:updateFrequency>1</sy:updateFrequency>
       <docs>http://backend.userland.com/rss</docs>




<div class="xar-mod-head"><span class="xar-mod-title">Programming Topics + Student Code Critiques from CVu journal. + CVu Journal Vol 11, #3 - Apr 1999</span></div>

<table border="0" cellpadding="1" cellspacing="0">
    <tbody>
    <tr>
        <td valign="top">
            Browse in :
       </td>
       <td valign="top">

                                            <a href="https://members.accu.org/index.php/articles/">All</a>

                     &gt;                         <a href="https://members.accu.org/index.php/articles/c13/">Topics</a>

                     &gt;                         <a href="https://members.accu.org/index.php/articles/c65/">Programming</a>
<br />

                                            <a href="https://members.accu.org/index.php/articles/">All</a>

                     &gt;                         <a href="https://members.accu.org/index.php/articles/c184/">Journal Columns</a>

                     &gt;                         <a href="https://members.accu.org/index.php/articles/c183/">Code Critique</a>
<br />

                                            <a href="https://members.accu.org/index.php/articles/">All</a>

                     &gt;                         <a href="https://members.accu.org/index.php/articles/c76/">Journals</a>

                     &gt;                         <a href="https://members.accu.org/index.php/articles/c77/">CVu</a>

                     &gt;                         <a href="https://members.accu.org/index.php/articles/c132/">113</a>
<br />

                                            <a href="https://members.accu.org/index.php/articles/c65-183-132/">Any of these categories</a>

                    -                        <a href="https://members.accu.org/index.php/articles/c65+183+132/">All of these categories</a>
<br />
</td>
   </tr>
   </tbody>
</table>




<div class="xar-error">
   <p>
 <strong>Note:</strong> when you create a new publication type,
the articles module will automatically use the templates
<em>user-display-[publicationtype].xt</em>
and <em>user-summary-[publicationtype].xt</em>.
If those templates do not exist when you try to preview or display a new article,
you'll get this warning :-)  Please place your own templates in themes/<em>yourtheme</em>/modules/articles . The templates will get the extension .xt there. </p>
</div>
<div class="xar-norm xar-standard-box-padding">
   <h1><strong>Title:</strong>&nbsp;Questions &amp; Answers</h1>
<p><strong>Author:</strong>&nbsp;</p>
<p>
<strong>Date:</strong> 03 April 1999 13:15:30 +01:00 or Sat, 03 April 1999 13:15:30 +01:00</p>
<p><strong>Summary:</strong>&nbsp;</p>
<p><strong>Body:</strong>&nbsp;<div class="sect1" lang="en">
<div class="titlepage">
<h2><a name="d0e20" id="d0e20"></a></h2>
</div>
<p>I do not have much this time so I have grabbed this piece of
help I supplied to a student.</p>
</div>
<div class="sect1" lang="en">
<div class="titlepage">
<h2><a name="d0e24" id="d0e24"></a>Confusing a
Call with a Declaration</h2>
</div>
<p>Forgive me, I took the liberty to take your address from the
message boards on C++.</p>
<p class="c2"><span class="remark">OK I will have a look this time,
but please consider becoming a student member of ACCU (see
www.accu.org) where we have a reflector dedicated to helping people
with their code.</span></p>
<p>If you have a few minutes, please help me figure out why this
C++ program compiles, runs, but does not properly execute the
convert from upper to lower case function? This assignment is due
Thursday(01/21/99) :-(</p>
<p>Programming problem: Write a program that requests a user to
enter a string. Convert the string to lower case using a function
you create. Your function should be stored in an external library
file which you include in your C++ program using the #include
directive. Beginning of main program:</p>
<pre class="programlisting">
#include &lt;iostream.h&gt;
</pre>
<p class="c2"><span class="remark">this is classic C++ standard C++
uses <tt class="literal">#include &lt;iostream&gt;</tt></span></p>
<pre class="programlisting">
&lt;snip&gt;
#include &lt;stdio.h&gt;
</pre>
<p class="c2"><span class="remark">why this as well as <tt class=
"filename">iostream.h</tt>, you should generally choose only one.
It is not wrong to use features from both but it usually shows a
lack of thought.</span></p>
<pre class="programlisting">
#include &quot;convertc.h&quot;

const dimensions = 30;
</pre>
<p class="c2"><span class="remark">good, nice to see you avoid the
style error of writing in all upper case however you need to learn
to avoid implicit <tt class="type">int</tt> because C++ (and the
next version of C) have removed it. In other words you must write
<tt class="type">int const</tt> (or if you insist, <tt class=
"type">const int</tt>) instead of your plain <tt class=
"literal">const</tt>.</span></p>
<pre class="programlisting">
typedef char string[dimensions];
</pre>
<p class="c2"><span class="remark">both the above should be in
<tt class="filename">convertc.h</tt> (or another header so that the
same rules can be applied throughout your program -- by placing
them in a header file you only have a single change when you decide
to do so.</span></p>
<p class="c2"><span class="remark"><tt class="varname">string</tt>
is a very bad choice of name -- string has a specific meaning in
C++ and all global identifiers starting with <tt class=
"varname">str</tt> followed by a lower case letter are reserved by
both C and C++ for use by compiler implementors.</span></p>
<pre class="programlisting">
void convert_case();
</pre>
<p class="c2"><span class="remark">that prototype belongs in your
header file</span></p>
<pre class="programlisting">
void main()
</pre>
<p class="c2"><span class="remark">In both C and C++ main is
required to return <tt class="type">int</tt> (despite all the books
and compilers telling you otherwise)</span></p>
<pre class="programlisting">
{
string your_name;
  cout &lt;&lt; &quot;Please enter your name: &quot;;
  cin  &gt;&gt; your_name;
  void convert_case ();
</pre>
<p class="c2"><span class="remark">THIS IS THE CRITICAL
ERROR</span></p>
<p class="c2"><span class="remark">leave out that <tt class=
"type">void</tt> (it makes this a declaration of a version of
<tt class="function">convert_case()</tt> that takes no arguments
rather than the call you intended)</span></p>
<pre class="programlisting">
  cout &lt;&lt; &quot; Hello and a nice day to you &quot; 
     &lt;&lt; your_name;
</pre>
<p class="c2"><span class="remark">to keep silly compilers happy
include <tt class="literal">return 0;</tt> the language does not
need it but MS compilers are too stupid to know that.</span></p>
<pre class="programlisting">
}
****end of main program****
****begin of library file****
#ifdef convertc.h
</pre>
<p class="c2"><span class="remark">Do not spell preprocessor names
with lower case letters and a dot is not an allowed symbol in a
preprocessor identifier. In addition if this is intended to be a
file sentinel it is wrong. It should be <tt class="literal">#ifndef
CONVERTC_H</tt></span></p>
<pre class="programlisting">
const dimensions = 30;
</pre>
<p class="c2"><span class="remark">See above re omitted <tt class=
"type">int</tt>.</span></p>
<pre class="programlisting">
typedef char string[dimensions];
  // this is the function to convert the string to lower case
  void convert_case(string str1);
</pre>
<p class="c2"><span class="remark">Your header file should end here
and the definition belongs in its own source code file with
appropriate includes (one of which will be for <tt class=
"filename">convertc.h</tt>)</span></p>
<pre class="programlisting">
void convert_case(string str1)
{
  int limit = strlen(str1);
  for (int x = 0; x &lt; limit; ++x)
  str1[x] = _tolower(str1[x]);
</pre>
<p class="c2"><span class="remark">why are you calling an
implementors function (with leading underscore) instead of the
standard function <tt class="function">tolower()</tt>?</span></p>
<pre class="programlisting">
}
#define convertc.h
</pre>
<p class="c2"><span class="remark">Conventionally this line
(corrected) is placed immediately after the <tt class=
"literal">#ifndef</tt> line.</span></p>
<pre class="programlisting">
#endif
&gt;****end of library file****
</pre>
<p class="c2"><span class="remark">I hope that helps.</span></p>
<p>(Of course being a typical student he never replied &#9786;</p>
</div>
</p>
<p><strong>Notes:</strong>&nbsp;</p>
<p><em>More fields may be available via dynamicdata ..</em></p>
</div>
</channel>
</rss>
