⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 3exerc.html

📁 Visual C++ has been one of most effective tool for the large industrial applications. This book is t
💻 HTML
字号:
<html>
<head>
	<title>Exercises</title>
	<link rel="stylesheet" href="rs.css" tppabs="http://www.relisoft.com/book/rs.css">
</head>

<body background="margin.gif" tppabs="http://www.relisoft.com/book/images/margin.gif" bgcolor="#FFFFDC">

<!-- Main Table -->
<table cellpadding="6">
    <tr>
    <td width="78">
	&nbsp;
    <td>
<h3>Exercises</h3>

<ol>

<li>Implement the function:



<!-- Code --><table width="100%" cellspacing=10><tr>	<td class=codetable>
<pre>void StrCpy (char* strDest, char* strSrc);</pre>
</table><!-- End Code -->

that copies the source string up to and with the terminating null into the destination string. The destination string is assumed to have enough space (unfortunately, we can抰 simply assert it). Use the &quot;indexing the array&quot; method rather than pointers to char.


<li>Implement the function

<!-- Code --><table width="100%" cellspacing=10><tr>	<td class=codetable>
<pre>int StrCmp (char* str1, char* str2);</pre>
</table><!-- End Code -->

that lexicographically compares two strings. It returns zero when the strings are equal. Otherwise it returns a number greater than or less than zero if the first differing character in string 1 corresponds to, respectively, greater or smaller ASCII code than the corresponding character in string 2. The comparison stops when a null character is encountered in either string. If string 1 is longer, a positive number is returned; if string 2 is longer, a negative number is returned. Use the index implementation.

<li>Another of these old &quot;optimizing&quot; tricks is to run a loop backwards. Instead of incrementing the counter we decrement it until it becomes negative or reaches zero. (At some point every programmer gets bitten by this trick when the loop variable is of the unsigned type.)


<p>Find a bug and rewrite the function


<!-- Code --><table width="100%" cellspacing=10><tr>	<td class=codetable>
<pre>void StrNCpy (char* strDest, char* strSrc, size_t len)
{
      while (--len &gt;= 0)
            *strDest++ = *strSrc++;
}</pre>
</table><!-- End Code -->

where <var>size_t</var> is some unsigned integral type defined, for instance, in <var>cstring</var>. Get rid of the &quot;optimizing&quot; tricks introduced here by a human compiler.
</ol>


</table>
<!-- End Main Table -->
</body>
</html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -