{"id":110,"date":"2026-03-19T22:39:14","date_gmt":"2026-03-19T14:39:14","guid":{"rendered":"https:\/\/www.caldm.cn\/?p=110"},"modified":"2026-03-19T22:39:14","modified_gmt":"2026-03-19T14:39:14","slug":"c10-%e5%ad%97%e7%ac%a6%e4%b8%b2%e5%92%8c%e5%ad%97%e7%ac%a6%e4%b8%b2%e5%87%bd%e6%95%b0","status":"publish","type":"post","link":"https:\/\/www.caldm.cn\/index.php\/2026\/03\/19\/c10-%e5%ad%97%e7%ac%a6%e4%b8%b2%e5%92%8c%e5%ad%97%e7%ac%a6%e4%b8%b2%e5%87%bd%e6%95%b0\/","title":{"rendered":"C10 \u5b57\u7b26\u4e32\u548c\u5b57\u7b26\u4e32\u51fd\u6570"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">1. \u8868\u793a\u5b57\u7b26\u4e32\u548c\u5b57\u7b26\u4e32I\/O<\/h2>\n\n\n\n<p>\u5b57\u7b26\u4e32\u662f\u4ee5\u7a7a\u5b57\u7b26\uff08<code>\\0<\/code>\uff09\u7ed3\u5c3e\u7684<code>char<\/code>\u7c7b\u578b\u6570\u7ec4\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">1.1 \u5728\u7a0b\u5e8f\u4e2d\u5b9a\u4e49\u5b57\u7b26\u4e32<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\">1.1.1 \u5b57\u7b26\u4e32\u5b57\u9762\u91cf\uff08\u5b57\u7b26\u4e32\u5e38\u91cf\uff09<\/h4>\n\n\n\n<p>\u7528\u53cc\u5f15\u53f7\u62ec\u8d77\u6765\u7684\u5185\u5bb9\u79f0\u4e3a<strong>\u5b57\u7b26\u4e32\u5b57\u9762\u91cf<\/strong>\uff08<em>string literal<\/em>\uff09\uff0c\u4e5f\u53eb\u4f5c<strong>\u5b57\u7b26\u4e32\u5e38\u91cf<\/strong>\uff08<em>string constant<\/em>\uff09\u3002\u53cc\u5f15\u53f7\u4e2d\u7684\u5b57\u7b26\uff0c\u7f16\u8bd1\u5668\u4f1a\u81ea\u52a8\u5728\u672b\u5c3e\u6dfb\u52a0<code>\\0<\/code>\u3002<\/p>\n\n\n\n<p>ANSI C\u6807\u51c6\u5f00\u59cb\uff0c\u5982\u679c\u5b57\u7b26\u4e32\u5b57\u9762\u91cf\u4e4b\u95f4\u6ca1\u6709\u95f4\u9694\uff0c\u6216\u7528\u7a7a\u767d\u5b57\u7b26\u5206\u9694\uff0cC\u4f1a\u5c06\u5176\u89c6\u4e3a\u4e32\u8054\u8d77\u6765\u7684\u5b57\u7b26\u4e32\u5b57\u9762\u91cf\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>char ca1&#91;20] = \"Hello\"\" World\";\n\/\/ \u4e0e\u4e0b\u9762\u7b49\u4ef7\nchar ca2&#91;20] = \"Hello World\";\n<\/code><\/pre>\n\n\n\n<p>\u5b57\u7b26\u4e32\u5c5e\u4e8e<strong>\u9759\u6001\u5b58\u50a8\u7c7b\u522b<\/strong>\uff08<em>static storage class<\/em>\uff09\u3002\u5982\u679c\u5728\u51fd\u6570\u4e2d\u4f7f\u7528\u5b57\u7b26\u4e32\u5b57\u9762\u91cf\uff0c\u8be5\u5b57\u7b26\u4e32\u53ea\u4f1a\u88ab\u50a8\u5b58\u4e00\u6b21\uff0c\u5728\u6574\u4e2a\u7a0b\u5e8f\u7684\u751f\u547d\u671f\u5185\u5b58\u5728\u3002\u5373\u4f7f\u51fd\u6570\u88ab\u8c03\u7528\u591a\u6b21\u3002<\/p>\n\n\n\n<p>\u7528\u53cc\u5f15\u53f7\u62ec\u8d77\u6765\u7684\u5185\u5bb9\u88ab\u89c6\u4e3a\u6307\u5411\u8be5\u5b57\u7b26\u4e32\u50a8\u5b58\u4f4d\u7f6e\u7684\u6307\u9488\u3002\u7c7b\u4f3c\u6570\u7ec4\u540d\u662f\u6307\u5411\u6570\u7ec4\u9996\u5143\u7d20\u7684\u6307\u9488\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#include &lt;stdio.h&gt;\nint main() {\n    printf(\"%s %p %c\\n\", \"Caldm\", \"CALDM\", \"caldm\");\n    return 0;\n}\n\/\/\u8f93\u51fa\u7ed3\u679c\n\/\/Caldm 00007FF75CBC9C2C c\n<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">1.1.2 \u5b57\u7b26\u4e32\u6570\u7ec4\u548c\u521d\u59cb\u5316<\/h4>\n\n\n\n<p>\u7528\u6307\u5b9a\u7684\u5b57\u7b26\u4e32\u521d\u59cb\u5316\u6570\u7ec4\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>const char s&#91;20] = \"Hello World\";\n<\/code><\/pre>\n\n\n\n<p>\u5bf9\u6bd4\u6807\u51c6\u7684\u6570\u7ec4\u521d\u59cb\u5316\u4f1a\u7b80\u5355\u8bb8\u591a\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>const char s&#91;20] = {'H', 'e', 'l', 'l', 'o', ' ', 'W', 'o', 'r', 'l', 'd', '\\0'};\n<\/code><\/pre>\n\n\n\n<p>\u5fc5\u987b\u6dfb\u52a0\u672b\u5c3e\u7684<code>\\0<\/code>\uff0c\u5426\u5219\u5219\u5c31\u4e0d\u662f\u4e00\u4e2a\u5b57\u7b26\u4e32\uff0c\u800c\u662f\u4e00\u4e2a\u5b57\u7b26\u6570\u7ec4\u3002<\/p>\n\n\n\n<p>\u5bf9\u4e8e<code>char<\/code>\u7c7b\u578b\u7684\u6570\u7ec4\uff0c\u6240\u6709\u672a\u88ab\u4f7f\u7528\u7684\u5143\u7d20\u4f1a\u88ab\u8bbe\u7f6e\u4e3a<code>'0'<\/code>\uff08\u6ce8\u610f\u662f<code>char<\/code>\u7c7b\u578b\u76840\uff09\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>const char s&#91;] = \"All in the game, all in game.\";\n<\/code><\/pre>\n\n\n\n<p>\u8ba9\u7f16\u8bd1\u5668\u786e\u5b9a\u521d\u59cb\u5316\u5b57\u7b26\u6570\u7ec4\u7684\u5927\u5c0f\u5f88\u5408\u7406\uff0c\u4e5f\u5f88\u65b9\u4fbf\uff0c\u5904\u7406\u5b57\u7b26\u7684\u51fd\u6570\u5927\u90e8\u5206\u90fd\u4e0d\u77e5\u9053\u6570\u7ec4\u7684\u957f\u5ea6\uff0c\u800c\u662f\u901a\u8fc7\u67e5\u627e\u672b\u5c3e\u7684\u7a7a\u5b57\u7b26\u6765\u786e\u5b9a\u5b57\u7b26\u4e32\u7684\u672b\u5c3e\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">1.1.3 \u6570\u7ec4\u548c\u6307\u9488<\/h4>\n\n\n\n<p>\u5f53\u4f60\u7528\u6307\u9488\u6307\u5411\u5b57\u7b26\u4e32\u5b57\u9762\u91cf\u65f6\uff0c\u5e76\u5c1d\u8bd5\u4fee\u6539\u65f6\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#include &lt;stdio.h&gt;\nint main() {\n    char* p1 = \"Klingon\";\n    p1&#91;0] = 'F';\n    printf(\"Klingon\");\n    printf(\": Beware the %ss!\\n\", \"Klingon\");\n    return 0;\n}\n\/\/\u5b9e\u9645\u8f93\u51fa\n\/\/Flingon: Beware the Flingons!\n<\/code><\/pre>\n\n\n\n<p>\u56e0\u4e3a\u7f16\u8bd1\u5668\u4f7f\u7528\u540c\u4e00\u4e2a\u526f\u672c\u6765\u8868\u793a\u76f8\u540c\u7684\u5b57\u7b26\u4e32\u5b57\u9762\u91cf\uff0c\u6240\u4ee5\u5f53\u4fee\u6539\u5b57\u9762\u91cf\u65f6\uff0c\u5176\u4ed6\u4f7f\u7528\u76f8\u540c\u5b57\u7b26\u4e32\u5b57\u9762\u91cf\u7684\u5730\u65b9\u4e5f\u4f1a\u540c\u6b65\u4fee\u6539\u3002<\/p>\n\n\n\n<p>\u26a0\ufe0f<strong>\u6ce8\u610f<\/strong>\uff1a\u5f53\u4fee\u6539\u5b57\u7b26\u4e32\u65f6\uff0c\u4e0d\u8981\u7528\u6307\u9488\u6307\u5411\u5b57\u7b26\u4e32\u5b57\u9762\u91cf\u3002\u5efa\u8bae\u628a\u6307\u9488\u521d\u59cb\u5316\u4e3a\u5b57\u7b26\u4e32\u5b57\u9762\u91cf\u65f6\uff0c\u4f7f\u7528<code>const<\/code>\u9650\u5b9a\u7b26\u3002<\/p>\n\n\n\n<p>\u53ef\u4ee5\u6307\u5411\u5b57\u7b26\u4e32\u53d8\u91cf\uff0c\u56e0\u4e3a\u5b57\u7b26\u4e32\u53d8\u91cf\u4e2d\u5b58\u50a8\u7684\u662f\u5b57\u7b26\u4e32\u5b57\u9762\u91cf\u7684\u526f\u672c\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">1.1.4 \u5b57\u7b26\u4e32\u6570\u7ec4<\/h4>\n\n\n\n<p>\u6307\u5411\u5b57\u7b26\u4e32\u7684\u6307\u9488\u6570\u7ec4\u548c<code>char<\/code>\u7c7b\u578b\u6570\u7ec4\u7684\u6570\u7ec4\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#include &lt;stdio.h&gt;\nint main() {\n    const char* arrPt&#91;4] = {\n        \"\u96cf\u7a1a\u5fc3\u9ad8\u5411\u4e91\u5dc5\uff0c\u60dc\u662f\u7a77\u7fc5\u8f6f\u722a\u5c16\u3002\",\n        \"\u6eda\u6eda\u957f\u6c5f\u4e1c\u901d\u6c34\",\n        \"\u541b\u4e0d\u89c1\uff0c\u5927\u6cb3\u4e4b\u6c34\u5929\u4e0a\u6765\",\n        \"\u4ed6\u671b\u8f66\u5916\u770b\u4e86\u770b\uff0c\u8bf4\uff0c\u201c\u6211\u4e70\u51e0\u4e2a\u6a58\u5b50\u53bb\u3002\u4f60\u5c31\u5728\u6b64\u5730\uff0c\u4e0d\u8981\u8d70\u52a8\u3002\u201d\",\n    };\n    const char arrStr&#91;4]&#91;100] = {\n        {\"\u96cf\u7a1a\u5fc3\u9ad8\u5411\u4e91\u5dc5\uff0c\u60dc\u662f\u7a77\u7fc5\u8f6f\u722a\u5c16\u3002\"},\n        {\"\u6eda\u6eda\u957f\u6c5f\u4e1c\u901d\u6c34\"},\n        {\"\u541b\u4e0d\u89c1\uff0c\u5927\u6cb3\u4e4b\u6c34\u5929\u4e0a\u6765\"},\n        {\"\u4ed6\u671b\u8f66\u5916\u770b\u4e86\u770b\uff0c\u8bf4\uff0c\u201c\u6211\u4e70\u51e0\u4e2a\u6a58\u5b50\u53bb\u3002\u4f60\u5c31\u5728\u6b64\u5730\uff0c\u4e0d\u8981\u8d70\u52a8\u3002\u201d\"},\n    };\n    for (int i = 0; i &lt; 4; i++) {\n        printf(\"arrPt:  %s\\n\", arrPt&#91;i]);\n        printf(\"arrStr: %s\\n\", arrStr&#91;i]);\n    }\n    printf(\"sizeof(arrPt): %d, sizeof(s2): %d\\n\", (int)sizeof(arrPt), (int)sizeof(arrStr));\n    return 0;\n}\n\/\/\u8f93\u51fa\u7ed3\u679c\n\/\/arrPt:  \u96cf\u7a1a\u5fc3\u9ad8\u5411\u4e91\u5dc5\uff0c\u60dc\u662f\u7a77\u7fc5\u8f6f\u722a\u5c16\u3002\n\/\/arrStr: \u96cf\u7a1a\u5fc3\u9ad8\u5411\u4e91\u5dc5\uff0c\u60dc\u662f\u7a77\u7fc5\u8f6f\u722a\u5c16\u3002\n\/\/arrPt:  \u6eda\u6eda\u957f\u6c5f\u4e1c\u901d\u6c34\n\/\/arrStr: \u6eda\u6eda\u957f\u6c5f\u4e1c\u901d\u6c34\n\/\/arrPt:  \u541b\u4e0d\u89c1\uff0c\u5927\u6cb3\u4e4b\u6c34\u5929\u4e0a\u6765\n\/\/arrStr: \u541b\u4e0d\u89c1\uff0c\u5927\u6cb3\u4e4b\u6c34\u5929\u4e0a\u6765\n\/\/arrPt:  \u4ed6\u671b\u8f66\u5916\u770b\u4e86\u770b\uff0c\u8bf4\uff0c\u201c\u6211\u4e70\u51e0\u4e2a\u6a58\u5b50\u53bb\u3002\u4f60\u5c31\u5728\u6b64\u5730\uff0c\u4e0d\u8981\u8d70\u52a8\u3002\u201d\n\/\/arrStr: \u4ed6\u671b\u8f66\u5916\u770b\u4e86\u770b\uff0c\u8bf4\uff0c\u201c\u6211\u4e70\u51e0\u4e2a\u6a58\u5b50\u53bb\u3002\u4f60\u5c31\u5728\u6b64\u5730\uff0c\u4e0d\u8981\u8d70\u52a8\u3002\u201d\n\/\/sizeof(arrPt): 32, sizeof(arrStr): 400\n<\/code><\/pre>\n\n\n\n<p>\u4e24\u8005\u5728\u6253\u5370\u6548\u679c\u4e0a\u76f8\u540c\uff0c\u533a\u522b\u5728\u4e8e\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>arrPt<\/code>\u5b58\u50a8\u7684\u662f\u4e94\u4e2a\u6307\u9488\uff0c\u5e76\u4e14\u8fd9\u4e9b\u6307\u9488\u6307\u5411\u5b57\u7b26\u4e32\u5b57\u9762\u91cf\uff0c<code>arrStr<\/code>\u5b58\u50a8\u7684\u662f\u4e94\u4e2a\u5b57\u7b26\u4e32\u6570\u7ec4\u3002<\/li>\n\n\n\n<li><code>arrPt<\/code>\u7684\u6bcf\u4e2a\u5b57\u7b26\u4e32\u7684\u957f\u5ea6\u662f\u4e0d\u540c\u7684\uff0c\u800c<code>arrStr<\/code>\u5b58\u50a8\u7684\u6bcf\u4e2a\u6570\u7ec4\u7684\u957f\u5ea6\u662f\u76f8\u540c\u7684\uff0c\u4e14\u957f\u5ea6\u81f3\u5c11\u4e3a\u6700\u957f\u5b57\u7b26\u4e32\u7684\u957f\u5ea6\u3002\u4ece\u672b\u5c3e\u7684\u6253\u5370\u4e2d\u53ef\u4ee5\u770b\u51fa<code>arrPt<\/code>\u7684\u5927\u5c0f\u662f32\uff0c<code>arrStr<\/code>\u7684\u5927\u5c0f\u662f400\u3002<\/li>\n\n\n\n<li><code>arrStr<\/code>\u521d\u59cb\u5316\u65f6\uff0c\u7f16\u8bd1\u5668\u5148\u5728\u9759\u6001\u5b58\u50a8\u533a\u4e2d\u521b\u5efa\u5b57\u7b26\u4e32\u5b57\u9762\u91cf\uff0c\u7136\u540e\u518d\u5c06\u5176\u8d4b\u7ed9<code>arrStr<\/code>\uff0c\u56e0\u6b64<code>arrStr<\/code>\u5728\u901f\u5ea6\u4e0a\u6bd4<code>arrPt<\/code>\u7a0d\u6162\u3002<\/li>\n\n\n\n<li><code>arrStr<\/code>\u4e2d\u7684\u5185\u5bb9\u53ef\u4ee5\u66f4\u6539\uff0c<code>arrPt<\/code>\u4e2d\u7684\u5185\u5bb9\u4e0d\u53ef\u4ee5\u66f4\u6539\u3002<\/li>\n<\/ul>\n\n\n\n<p>\u5982\u679c\u8981\u7528\u6570\u7ec4\u5b58\u50a8\u4e00\u7cfb\u5217\u7528\u4e8e\u663e\u793a\u7684\u5b57\u7b26\u4e32\uff0c\u4f18\u5148\u4f7f\u7528\u6307\u9488\u6570\u7ec4\u3002\u82e5\u9700\u8981\u66f4\u6539\u5185\u5bb9\uff0c\u5219\u4f7f\u7528\u4e8c\u7ef4\u5b57\u7b26\u6570\u7ec4\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">2. \u5b57\u7b26\u4e32\u8f93\u5165<\/h2>\n\n\n\n<p>\u60f3\u628a\u5b57\u7b26\u4e32\u8bfb\u5165\u7a0b\u5e8f\uff0c\u9700\u8981\u5148\u9884\u7559\u50a8\u5b58\u7a7a\u95f4\uff0c\u7136\u540e\u901a\u8fc7\u8f93\u5165\u51fd\u6570\u83b7\u53d6\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">2.1 \u5206\u914d\u7a7a\u95f4<\/h3>\n\n\n\n<p>\u7ed9\u5b57\u7b26\u4e32\u5206\u914d\u7a7a\u95f4\u65f6\uff0c\u5fc5\u987b\u6307\u5b9a\u5b57\u7b26\u4e32\u6570\u7ec4\u7684\u957f\u5ea6\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">2.2 <code>gets()<\/code>\u51fd\u6570<\/h3>\n\n\n\n<p><code>gets()<\/code>\u51fd\u6570\u4f1a\u8bfb\u53d6\u6574\u884c\u8f93\u5165\uff0c\u9047\u5230\u6362\u884c\u7b26\u65f6\u505c\u6b62\uff0c\u968f\u540e\u4e22\u5f03\u6362\u884c\u7b26\uff0c\u5728\u672b\u5c3e\u6dfb\u52a0<code>\\0<\/code>\u4f7f\u5176\u6210\u4e3a\u5b57\u7b26\u4e32\u3002<\/p>\n\n\n\n<p>\u5b83\u5e38\u4e0e<code>puts()<\/code>\u51fd\u6570\u914d\u5bf9\u4f7f\u7528\uff0c\u8be5\u51fd\u6570\u7528\u4e8e\u663e\u793a\u5b57\u7b26\u4e32\u5e76\u5728\u672b\u5c3e\u6dfb\u52a0\u6362\u884c\u7b26\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">2.2.1 <code>gets()<\/code>\u51fd\u6570\u7684\u95ee\u9898<\/h4>\n\n\n\n<p><code>gets()<\/code>\u51fd\u6570\u5e76\u4e0d\u77e5\u9053\u8f93\u5165\u5b57\u7b26\u7684\u591a\u5c11\uff0c\u5f53\u8f93\u5165\u5b57\u7b26\u5927\u4e8e\u9884\u7559\u7684\u50a8\u5b58\u7a7a\u95f4\u65f6\uff0c\u4f1a\u5bfc\u81f4<strong>\u7f13\u51b2\u533a\u6ea2\u51fa<\/strong>\uff08<em>buffer overflow<\/em>\uff09\u3002\u5982\u679c\u591a\u4f59\u7684\u5b57\u7b26\u53ea\u662f\u5360\u7528\u672a\u5206\u914d\u7684\u5185\u5b58\u7a7a\u95f4\uff0c \u90a3\u4e48\u8fd8\u6ca1\u6709\u95ee\u9898\uff0c\u82e5\u662f\u64e6\u9664\u4e86\u7a0b\u5e8f\u4e2d\u5176\u4ed6\u6570\u636e\uff0c\u5219\u4f1a\u5bfc\u81f4\u7a0b\u5e8f\u5f02\u5e38\u6216\u4e2d\u6b62\u3002<\/p>\n\n\n\n<p>\u4eceC99\u5f00\u59cb\uff0c\u4e0d\u518d\u5efa\u8bae\u4f7f\u7528<code>gets()<\/code>\u51fd\u6570\uff0cC11\u6807\u51c6\u6b63\u5f0f\u5e9f\u9664\u4e86<code>gets()<\/code>\u51fd\u6570\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">2.3 <code>gets()<\/code>\u7684\u66ff\u4ee3\u54c1<\/h3>\n\n\n\n<p>C11\u6807\u51c6\u4e4b\u524d\uff0c\u5e38\u7528<code>fgets()<\/code>\u4ee3\u66ff<code>gets()<\/code>\u3002C11\u6807\u51c6\u4e4b\u540e\uff0c\u7528<code>gets_s()<\/code>\u4ee3\u66ff<code>gets()<\/code>\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">2.3.1 <code>fgets()<\/code>\u51fd\u6570\u548c<code>fputs()<\/code>\u51fd\u6570<\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>fgets()<\/code>\u51fd\u6570\u7684\u7b2c\u4e8c\u4e2a\u53c2\u6570\u6307\u660e\u8bfb\u5165\u5b57\u7b26\u7684\u6700\u5927\u6570\u91cf\uff0c\u5982\u679c\u53c2\u6570\u503c\u4e3a<code>n<\/code>\uff0c\u5219\u53ea\u4f1a\u8bfb\u5165<code>n-1<\/code>\u4e2a\u5b57\u7b26\uff0c\u6216\u8005\u9047\u5230\u7b2c\u4e00\u4e2a\u6362\u884c\u7b26\u4e3a\u6b62\u3002<\/li>\n\n\n\n<li><code>fgets()<\/code>\u51fd\u6570\u8bfb\u5230\u7b2c\u4e00\u4e2a\u6362\u884c\u7b26\u65f6\u4f1a\u5c06\u5176\u4fdd\u5b58\uff0c\u8fd9\u4e0e<code>gets()<\/code>\u4e0d\u540c<\/li>\n\n\n\n<li><code>fgets()<\/code>\u51fd\u6570\u7b2c\u4e09\u4e2a\u53c2\u6570\u6307\u660e\u8bfb\u5165\u7684\u6587\u4ef6\uff0c\u5982\u679c\u4ece\u952e\u76d8\u8bfb\u5165\uff0c\u5219\u4ee5<code>stdin<\/code>\uff08\u8be5\u6807\u8bc6\u7b26\u5b9a\u4e49\u5728<code>stdio.h<\/code>\u4e2d\uff09\u4e3a\u53c2\u6570\u3002<\/li>\n<\/ul>\n\n\n\n<p><code>fgets()<\/code>\u5e38\u4e0e<code>fputs()<\/code>\u914d\u5bf9\u4f7f\u7528\uff0c<code>fputs()<\/code>\u51fd\u6570\u4e0d\u4f1a\u5728\u5b57\u7b26\u4e32\u672b\u5c3e\u6dfb\u52a0\u6362\u884c\uff0c\u5b83\u7684\u7b2c\u4e8c\u4e2a\u53c2\u6570\u6307\u660e\u5199\u5165\u7684\u6587\u4ef6\uff0c\u5982\u679c\u8981\u663e\u793a\u5728\u5c4f\u5e55\u4e0a\uff0c\u5219\u7528<code>stdout<\/code>\u4f5c\u4e3a\u53c2\u6570\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">2.3.2 <code>gets_s()<\/code>\u51fd\u6570<\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>gets_s()<\/code>\u51fd\u6570\u53ea\u4ece\u6807\u51c6\u8f93\u5165\u4e2d\u8bfb\u53d6\u6570\u636e\u3002<\/li>\n\n\n\n<li><code>gets_s()<\/code>\u51fd\u6570\u9047\u5230\u6362\u884c\u7b26\u65f6\u4f1a\u4e22\u5f03\u5b83\u3002<\/li>\n\n\n\n<li><code>gets_s()<\/code>\u51fd\u6570\u8bfb\u5230\u6700\u5927\u5b57\u7b26\u6570\u90fd\u6ca1\u6709\u8bfb\u5230\u6362\u884c\u7b26\u65f6\uff0c\u9996\u5148\u4f1a\u628a\u76ee\u6807\u6570\u7ec4\u4e2d\u7684\u9996\u5b57\u7b26\u8bbe\u7f6e\u4e3a\u7a7a\u5b57\u7b26\uff0c\u8bfb\u53d6\u5e76\u4e22\u5f03\u5269\u4f59\u8f93\u5165\u76f4\u81f3\u6362\u884c\u7b26\u6216\u6587\u4ef6\u672b\u5c3e\uff0c\u7136\u540e\u8fd4\u56de\u7a7a\u6307\u9488\uff08NULL\uff09\uff0c\u6700\u540e\u8c03\u7528\u4f9d\u8d56\u5b9e\u73b0\u7684\u5904\u7406\u51fd\u6570\uff0c\u8fd9\u53ef\u80fd\u4f1a\u4e2d\u6b62\u6216\u9000\u51fa\u7a0b\u5e8f\u3002<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">2.4 \u603b\u7ed3<\/h3>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th><\/th><th><code>gets()<\/code><\/th><th><code>fgets()<\/code><\/th><th><code>gets_s()<\/code><\/th><\/tr><\/thead><tbody><tr><td>\u6362\u884c\u7b26<\/td><td>\u4e22\u5f03<\/td><td>\u4fdd\u7559<\/td><td>\u4e22\u5f03<\/td><\/tr><tr><td>\u8f93\u5165<\/td><td><\/td><td>\u7528\u53c2\u6570\u6307\u5b9a\u8f93\u5165\uff08stdin\u6307\u5b9a\u4ece\u952e\u76d8\uff09<\/td><td>\u53ea\u80fd\u8bfb\u53d6\u6807\u51c6\u8f93\u5165<\/td><\/tr><tr><td>\u6700\u5927\u5b57\u7b26\u9650\u5236<\/td><td><\/td><td>\u7528\u53c2\u6570\u6307\u5b9a\uff0c\u6700\u5927\u8bfb\u53d6n-1\u4e2a\u5b57\u7b26<\/td><td>\u7528\u53c2\u6570\u6307\u5b9a\uff0c\u6700\u5927\u8bfb\u53d6n-1\u4e2a\u5b57\u7b26<\/td><\/tr><tr><td>\u8f93\u5165\u8fc7\u957f\u65f6<\/td><td>\u7f13\u51b2\u533a\u6ea2\u51fa<\/td><td><\/td><td>\u6dfb\u52a0\u7a7a\u5b57\u7b26\uff0c\u4e22\u5f03\u5269\u4f59\u8f93\u5165\uff0c\u8c03\u7528\u4f9d\u8d56\u5b9e\u73b0\u51fd\u6570\u7684\u201c\u5904\u7406\u51fd\u6570\u201d\uff0c\u53ef\u80fd\u4f1a\u4e2d\u6b62\u6216\u9000\u51fa\u7a0b\u5e8f<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">3. \u5b57\u7b26\u4e32\u8f93\u51fa<\/h2>\n\n\n\n<p>C\u6807\u51c6\u5e93\u67093\u4e2a\u7528\u4e8e\u6253\u5370\u5b57\u7b26\u4e32\u7684\u51fd\u6570\uff1a<code>puts()<\/code>\u3001<code>fputs()<\/code>\u3001<code>printf()<\/code>\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">3.1 <code>puts()<\/code>\u51fd\u6570<\/h3>\n\n\n\n<p><code>puts()<\/code>\u51fd\u6570\u63a5\u6536\u4e00\u4e2a\u5b57\u7b26\u4e32\u5730\u5740\u4f5c\u4e3a\u53c2\u6570\uff0c\u6253\u5370\u65f6\u4f1a\u5728\u672b\u5c3e\u6dfb\u52a0\u6362\u884c\u7b26\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">3.2 <code>fputs()<\/code>\u51fd\u6570<\/h3>\n\n\n\n<p><code>fputs()<\/code>\u51fd\u6570\u662f<code>puts()<\/code>\u51fd\u6570\u9488\u5bf9\u6587\u4ef6\u5b9a\u5236\u7684\u7248\u672c\u3002<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>fputs()<\/code>\u51fd\u6570\u63a5\u6536\u7b2c2\u4e2a\u53c2\u6570\u6307\u660e\u5199\u5165\u7684\u6587\u4ef6\uff0c\u5982\u679c\u6253\u5370\u5728\u663e\u793a\u5668\u4e0a\uff0c\u5219\u4f7f\u7528\u5b9a\u4e49\u5728<code>stdio.h<\/code>\u4e2d\u7684<code>stdout<\/code>\u4f5c\u4e3a\u53c2\u6570\u3002<\/li>\n\n\n\n<li><code>fputs()<\/code>\u51fd\u6570\u4e0d\u4f1a\u5728\u672b\u5c3e\u6dfb\u52a0\u6362\u884c\u7b26\u3002<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">3.3 <code>printf()<\/code>\u51fd\u6570<\/h3>\n\n\n\n<p><code>printf()<\/code>\u51fd\u6570\u540c\u6837\u63a5\u6536\u4e00\u4e2a\u5b57\u7b26\u4e32\u5730\u5740\u4f5c\u4e3a\u53c2\u6570\uff0c\u4e0d\u4f1a\u5728\u672b\u5c3e\u6dfb\u52a0\u6362\u884c\u7b26\uff0c\u5e76\u4e14\u5b83\u7684\u6548\u7387\u4e5f\u66f4\u4f4e\uff0c\u4f46\u662f<code>printf()<\/code>\u51fd\u6570\u80fd\u683c\u5f0f\u5316\u4e0d\u540c\u7684\u6570\u636e\u7c7b\u578b\uff0c\u5728\u6253\u5370\u591a\u4e2a\u5b57\u7b26\u4e32\u65f6\u66f4\u52a0\u7b80\u5355\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">4. \u5b57\u7b26\u4e32\u51fd\u6570<\/h2>\n\n\n\n<p>C\u63d0\u4f9b\u4e86\u591a\u4e2a\u5904\u7406\u5b57\u7b26\u4e32\u7684\u51fd\u6570\uff0cANSI C\u628a\u8fd9\u4e9b\u51fd\u6570\u653e\u5728<code>string.h<\/code>\u5934\u6587\u4ef6\u4e2d\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">4.1 <code>strlen()<\/code>\u51fd\u6570<\/h3>\n\n\n\n<p><code>strlen()<\/code>\u51fd\u6570\u7528\u4e8e\u7edf\u8ba1\u5b57\u7b26\u4e32\u7684\u957f\u5ea6\u3002\u7a7a\u5b57\u7b26\u4e0d\u4f1a\u8ba1\u7b97\u5728\u5b57\u7b26\u4e32\u957f\u5ea6\u5185\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">4.2 <code>strcat()<\/code>\u51fd\u6570<\/h3>\n\n\n\n<p><code>strcat()<\/code>\u51fd\u6570\u63a5\u53d7\u4e24\u4e2a\u5b57\u7b26\u4e32\u4f5c\u4e3a\u53c2\u6570\uff0c\u8be5\u51fd\u6570\u4f1a\u628a\u7b2c2\u4e2a\u5b57\u7b26\u4e32\u62fc\u63a5\u5728\u7b2c1\u4e2a\u5b57\u7b26\u4e32\u540e\u8fb9\uff0c\u5e76\u628a\u62fc\u63a5\u540e\u7684\u5b57\u7b26\u4e32\u4f5c\u4e3a\u7b2c1\u4e2a\u5b57\u7b26\u4e32\uff0c\u7b2c2\u4e2a\u5b57\u7b26\u4e32\u4e0d\u53d8\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#include &lt;stdio.h&gt;\n#include &lt;string.h&gt;\n\n#pragma warning(disable : 4996)\n\nint main() {\n    char s1&#91;20] = \"123\";\n    char s2&#91;10] = \"456\";\n    printf(\"s1: %-10s s2: %-10s\\n\", s1, s2);\n    strcat(s1, s2);\n    printf(\"s1: %-10s s2: %-10s\\n\", s1, s2);\n    return 0;\n}\n\n\/\/\u5b9e\u9645\u8f93\u51fa\n\/\/s1: 123        s2: 456\n\/\/s1: 123456     s2: 456\n<\/code><\/pre>\n\n\n\n<p>\u26a0\ufe0f<strong>\u6ce8\u610f<\/strong>\uff1a<code>strcat()<\/code>\u51fd\u6570\u65e0\u6cd5\u68c0\u67e5\u7b2c1\u4e2a\u6570\u7ec4\u80fd\u5426\u5bb9\u7eb3\u7b2c2\u4e2a\u5b57\u7b26\u4e32\u3002\u5982\u679c\u4e0d\u80fd\uff0c\u600e\u4f1a\u9020\u6210\u6ea2\u51fa\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">4.3 <code>strncat()<\/code>\u51fd\u6570<\/h3>\n\n\n\n<p><code>strncat()<\/code>\u51fd\u6570\u4e0e<code>strcat()<\/code>\u51fd\u6570\u7c7b\u4f3c\uff0c\u4e0d\u8fc7<code>strncat()<\/code>\u51fd\u6570\u7684\u7b2c3\u4e2a\u53c2\u6570\u6307\u5b9a\u4e86\u6700\u5927\u6dfb\u52a0\u5b57\u7b26\u6570\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#include &lt;stdio.h&gt;\n#include &lt;string.h&gt;\n\n#pragma warning(disable : 4996) \/\/ \u5ffd\u7565\u8fd9\u884c\u4ee3\u7801\n\nint main() {\n    char s1&#91;10] = \"123\";\n    char s2&#91;10] = \"456789\";\n    printf(\"s1: %-10s s2: %-10s\\n\", s1, s2);\n    strncat(s1, s2, 3);\n    printf(\"s1: %-10s s2: %-10s\\n\", s1, s2);\n    return 0;\n}\n\/\/\u5b9e\u9645\u8f93\u51fa\n\/\/s1: 123        s2: 456789\n\/\/s1: 123456     s2: 456789\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">4.4 <code>strcmp()<\/code>\u51fd\u6570<\/h3>\n\n\n\n<p>\u82e5\u76f4\u63a5\u6bd4\u8f83\u4e24\u4e2a\u5b57\u7b26\u4e32\uff0c\u5982<code>s1 == s2<\/code>\uff0c\u90a3\u4e48\u5b9e\u9645\u6bd4\u8f83\u7684\u5e76\u4e0d\u662f\u5b57\u7b26\u4e32\uff0c\u800c\u662f\u4e24\u4e2a\u5b57\u7b26\u4e32\u9996\u5b57\u7b26\u7684\u5730\u5740\uff0c\u6240\u4ee5\u8fd9\u4e2a\u6761\u4ef6\u8868\u8fbe\u5f0f\u7684\u7ed3\u679c\u6c38\u8fdc\u4e3a\u5047\u503c\u3002<\/p>\n\n\n\n<p>\u4f7f\u7528C\u6807\u51c6\u5e93\u4e2d\u7684<code>strcmp()<\/code>\u51fd\u6570\u53ef\u4ee5\u6bd4\u8f83\u4e24\u4e2a\u5b57\u7b26\u4e32\u7684\u5185\u5bb9\uff0c\u5185\u5bb9\u76f8\u540c\u8fd4\u56de0\uff0c\u5426\u5219\u8fd4\u56de\u975e0\u503c\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>strcpm(string1, string2);\n<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">4.4.1 <code>strcmp()<\/code>\u51fd\u6570\u7684\u8fd4\u56de\u503c<\/h4>\n\n\n\n<p>\u5f53\u4e24\u4e2a\u5b57\u7b26\u4e32\u5185\u5bb9\u4e0d\u540c\u65f6\uff0c<code>strcmp()<\/code>\u51fd\u6570\u8fd4\u56de\u975e0\u503c\uff0c\u51c6\u786e\u5730\u8bf4\uff0c\u8fd4\u56de\u7684\u662f\u4e24\u4e2a\u503c\u7684ASCII\u7801\u4e4b\u5dee\u3002<\/p>\n\n\n\n<p>\u26a0\ufe0f<strong>\u6ce8\u610f<\/strong>\uff1aC\u5e76\u6ca1\u6709\u89c4\u5b9a<code>strcmp()<\/code>\u4e00\u5b9a\u8fd4\u56de\u4e24\u4e2a\u503c\u7684ASCII\u7801\u4e4b\u5dee\uff0c\u5927\u90e8\u5206\u7684\u5b9e\u73b0\u90fd\u53ea\u8fd4\u56de-1\u30010\u30011\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#include &lt;stdio.h&gt;\n#include &lt;string.h&gt;\n\nint main() {\n    printf(\"A D: %d\\n\", strcmp(\"A\", \"D\"));\n    printf(\"A A: %d\\n\", strcmp(\"A\", \"A\"));\n    printf(\"D A: %d\\n\", strcmp(\"D\", \"A\"));\n    return 0;\n}\n\/\/\u8fd9\u91cc\u8fd4\u56de\u7684\u5c31\u4e0d\u662fASCII\u7801\u4e4b\u5dee\uff0c\u53ea\u662f-1\u30010\u30011\n\/\/A D: -1\n\/\/A A: 0\n\/\/D A: 1\n<\/code><\/pre>\n\n\n\n<p><code>strcpm()<\/code>\u51fd\u6570\u4f1a\u6bd4\u8f83\u4e24\u4e2a\u5b57\u7b26\u4e32\u7684\u6bcf\u4e00\u5bf9\u5b57\u7b26\uff0c\u76f4\u5230\u53d1\u73b0\u7b2c\u4e00\u5bf9\u4e0d\u540c\u7684\u5b57\u7b26\u4e3a\u6b62\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">4.5 <code>strncpm()<\/code><\/h3>\n\n\n\n<p><code>strncpm()<\/code>\u51fd\u6570\u4e0e<code>strcpm()<\/code>\u7c7b\u4f3c\uff0c\u4f46\u53ef\u4ee5\u6dfb\u52a0\u7b2c3\u4e2a\u53c2\u6570\uff0c\u8868\u793a\u53ea\u5bf9\u6bd4\u5230\u7b2cn\u4e2a\u5b57\u7b26\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#include &lt;stdio.h&gt;\n#include &lt;string.h&gt;\n\nint main() {\n    printf(\"123456 123123: %d\\n\", strncmp(\"123456\", \"123123\", 3));\n    printf(\"123456 123123: %d\\n\", strncmp(\"123456\", \"123123\", 4));\n    return 0;\n}\n\/\/\u5b9e\u9645\u8f93\u51fa\n\/\/123456 123123: 0\n\/\/123456 123123: 1\n<\/code><\/pre>\n\n\n\n<p>\u4ece\u4f8b\u5b50\u4e2d\u53ef\u4ee5\u770b\u51fa\uff0c\u7b2c\u4e00\u6b21<code>strncmp()<\/code>\u51fd\u6570\u53ea\u6bd4\u8f83\u5230\u7b2c3\u4e2a\u5b57\u7b26\uff0c\u56e0\u6b64\u6ca1\u6709\u53d1\u73b0\u4e24\u4e2a\u5b57\u7b26\u4e32\u7684\u4e0d\u540c\uff0c\u800c\u7b2c\u4e8c\u6b21<code>strncmp()<\/code>\u51fd\u6570\u6bd4\u8f83\u5230\u7b2c4\u4e2a\u5b57\u7b26\uff0c\u56e0\u6b64\u53d1\u73b0\u4e24\u4e2a\u5b57\u7b26\u4e32\u7684\u4e0d\u540c\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">4.6 <code>strcpy()<\/code>\u548c<code>strncpy()<\/code>\u51fd\u6570<\/h3>\n\n\n\n<p><code>strcpy()<\/code>\u51fd\u6570\u7528\u4e8e\u62f7\u8d1d\u5b57\u7b26\u4e32\u3002\u8be5\u51fd\u6570\u63a5\u6536\u4e24\u4e2a\u5b57\u7b26\u4e32\u4f5c\u4e3a\u53c2\u6570\uff0c\u8fd4\u56de\u7b2c\u4e00\u4e2a\u5b57\u7b26\u4e32\u7684\u5730\u5740\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#include &lt;stdio.h&gt;\n#include &lt;string.h&gt;\n\n#pragma warning(disable : 4996)\n\nint main() {\n    char str1&#91;10] = \"123\";\n    char str2&#91;10] = \"456789\";\n    printf(\"str1: %10s, str2: %10s\\n\", str1, str2);\n    strcpy(str1, str2);\n    printf(\"str1: %10s, str2: %10s\\n\", str1, str2);\n    return 0;\n}\n\/\/\u5b9e\u9645\u8f93\u51fa\n\/\/str1:        123, str2:     456789\n\/\/str1:     456789, str2:     456789\n<\/code><\/pre>\n\n\n\n<p><code>strcpy()<\/code>\u7684\u7b2c\u4e00\u4e2a\u53c2\u6570\u4e0d\u5fc5\u6307\u5411\u5b57\u7b26\u4e32\u7684\u5f00\u59cb\uff0c\u8fd9\u6837\u53ef\u4ee5\u6307\u5b9a\u60f3\u62f7\u8d1d\u7684\u90e8\u5206\u3002<\/p>\n\n\n\n<p><code>strcpy(&amp;str1[1], str2);<\/code>\u6267\u884c\u540e\uff0c<code>str1<\/code>\u7684\u5185\u5bb9\u4e3a<code>\"1456789\"<\/code>\uff0c\u4ece\u8fd9\u91cc\u53ef\u4ee5\u770b\u5230\u7d22\u5f150\u7684\u4f4d\u7f6e\u5e76\u6ca1\u6709\u62f7\u8d1d\u7684\u5b57\u7b26\u4e32\u8986\u76d6\u3002<\/p>\n\n\n\n<p>\u4e0e<code>strcat()<\/code>\u7684\u95ee\u9898\u7c7b\u4f3c\uff0c<code>strcpy()<\/code>\u5e76\u6ca1\u6709\u68c0\u67e5\u7b2c1\u4e2a\u5b57\u7b26\u662f\u5426\u80fd\u5bb9\u7eb3\u7b2c2\u4e2a\u5b57\u7b26\uff0c<code>strncpy()<\/code>\u66f4\u5b89\u5168\uff0c\u5b83\u7684\u7b2c3\u4e2a\u53c2\u6570\u6307\u5b9a\u53ef\u62f7\u8d1d\u7684\u6700\u5927\u5b57\u7b26\u6570\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#include &lt;stdio.h&gt;\n#include &lt;string.h&gt;\n\nint main() {\n    char str1&#91;10] = \"123\";\n    char str2&#91;10] = \"456789\";\n    printf(\"str1: %10s, str2: %10s\\n\", str1, str2);\n    strncpy(str1, str2, 4);\n    printf(\"str1: %10s, str2: %10s\\n\", str1, str2);\n    return 0;\n}\n\/\/\u8f93\u51fa\u7ed3\u679c\n\/\/str1:        123, str2:     456789\n\/\/str1:       4567, str2:     456789\n<\/code><\/pre>\n\n\n\n<p>\u4f8b\u5b50\u4e2d\u7684<code>strncpy()<\/code>\u7684\u7b2c3\u4e2a\u53c2\u6570\u4e3a4\uff0c\u6240\u4ee5\u62f7\u8d1d\u7684\u7ed3\u679c\u53ea\u6709<code>str2<\/code>\u7684\u524d4\u4e2a\u3002<\/p>\n\n\n\n<p>\u540c\u6837\u7684\uff0c<code>strncpy()<\/code>\u7684\u7b2c1\u4e2a\u53c2\u6570\u4e5f\u4e0d\u4e00\u5b9a\u662f\u5b57\u7b26\u4e32\u7684\u5f00\u59cb\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">4.7 <code>sprintf()<\/code>\u51fd\u6570<\/h3>\n\n\n\n<p><code>sprintf()<\/code>\u51fd\u6570\u58f0\u660e\u5728<code>stdio.h<\/code>\u5934\u6587\u4ef6\u4e2d\uff0c\u8fd9\u4e0e\u5176\u4ed6\u5b57\u7b26\u4e32\u51fd\u6570\u4e0d\u540c\u3002<code>sprintf()<\/code>\u51fd\u6570\u4e0e<code>printf()<\/code>\u51fd\u6570\u7c7b\u4f3c\uff0c\u5b83\u662f\u628a\u6570\u636e\u5199\u5165\u5b57\u7b26\u4e32\uff0c\u800c\u4e0d\u662f\u6253\u5370\u5728\u5c4f\u5e55\u4e0a\u3002<\/p>\n\n\n\n<p><code>sprintf()<\/code>\u51fd\u6570\u63a5\u65363\u4e2a\u53c2\u6570\uff0c\u7b2c1\u4e2a\u53c2\u6570\u662f\u5b57\u7b26\u4e32\u5730\u5740\uff0c\u5176\u4f59\u4e24\u4e2a\u53c2\u6570\u4e0e\u4f7f\u7528<code>printf()<\/code>\u65f6\u586b\u5199\u7684\u53c2\u6570\u4e00\u81f4\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#include &lt;stdio.h&gt;\n#include &lt;string.h&gt;\n\nint main() {\n    char str&#91;30] = \"This is a number: %d\\n\";\n    printf(\"%s\", str);\n\tsprintf(str, \"This is a number: %d\\n\", 42);\n\tprintf(\"%s\", str);\n    return 0;\n}\n\/\/\u6570\u636e\u7c7b\u578b\n\/\/This is a number: %d\n\/\/This is a number: 42\n<\/code><\/pre>\n\n\n\n<p>\u26a0\ufe0f<strong>\u6ce8\u610f<\/strong>\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u82e5\u60f3\u5bf9\u5199\u5165\u7684\u6570\u636e\u8fdb\u884c\u683c\u5f0f\u5316\uff0c\u4fee\u6539<code>str<\/code>\u4e2d\u7684\u8f6c\u6362\u8bf4\u660e\u662f\u6ca1\u7528\u7684\uff0c\u9700\u8981\u5bf9<code>sprintf()<\/code>\u51fd\u6570\u4e2d\u7684\u7b2c2\u4e2a\u53c2\u6570\u8fdb\u884c\u4fee\u6539\u3002<\/li>\n\n\n\n<li><code>sprintf()<\/code>\u4e0d\u4f1a\u68c0\u67e5\u5199\u5165\u6570\u636e\u540e\uff0c\u6570\u7ec4\u80fd\u5426\u5bb9\u7eb3\u5b57\u7b26\u4e32\uff0c\u5f53\u5199\u5165\u6570\u636e\u540e\u5b57\u7b26\u4e32\u957f\u5ea6\u8d85\u8fc7\u6570\u7ec4\u65f6\uff0c\u540c\u6837\u4f1a\u6ea2\u51fa\uff0c\u5bfc\u81f4\u7a0b\u5e8f\u5f02\u5e38\u6216\u4e2d\u6b62\u3002<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">4.8 \u603b\u7ed3<\/h3>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>\u51fd\u6570\u540d<\/th><th>\u529f\u80fd\u63cf\u8ff0<\/th><th>\u53c2\u6570\u8bf4\u660e<\/th><th>\u8fd4\u56de\u503c<\/th><th>\u4e3b\u8981\u7279\u70b9\u4e0e\u6ce8\u610f\u4e8b\u9879<\/th><\/tr><\/thead><tbody><tr><td><strong><code>strlen()<\/code><\/strong>\u200b<\/td><td>\u8ba1\u7b97\u5b57\u7b26\u4e32\u957f\u5ea6\uff08\u4e0d\u5305\u542b\u7a7a\u5b57\u7b26<code>\\0<\/code>\uff09\u3002<\/td><td><code>const char* str<\/code><\/td><td>\u5b57\u7b26\u4e32\u7684\u5b57\u7b26\u6570\uff08<code>size_t<\/code>\u7c7b\u578b\uff09\u3002<\/td><td>\u4ec5\u7edf\u8ba1<code>\\0<\/code>\u4e4b\u524d\u7684\u5b57\u7b26\u3002<\/td><\/tr><tr><td><strong><code>strcat()<\/code><\/strong>\u200b<\/td><td>\u5c06\u6e90\u5b57\u7b26\u4e32<strong>\u62fc\u63a5<\/strong>\u5230\u76ee\u6807\u5b57\u7b26\u4e32<strong>\u672b\u5c3e<\/strong>\u3002<\/td><td><code>char* dest<\/code>, <code>const char* src<\/code><\/td><td>\u76ee\u6807\u5b57\u7b26\u4e32\u7684\u8d77\u59cb\u5730\u5740\uff08<code>char*<\/code>\uff09\u3002<\/td><td><strong>\u4e0d\u5b89\u5168<\/strong>\u3002\u4e0d\u68c0\u67e5\u76ee\u6807\u6570\u7ec4\u7a7a\u95f4\uff0c\u53ef\u80fd\u5bfc\u81f4\u7f13\u51b2\u533a\u6ea2\u51fa\u3002\u76ee\u6807\u5b57\u7b26\u4e32\u5fc5\u987b\u53ef\u4fee\u6539\u4e14\u6709\u8db3\u591f\u7a7a\u95f4\u3002<\/td><\/tr><tr><td><strong><code>strncat()<\/code><\/strong>\u200b<\/td><td>\u5c06\u6e90\u5b57\u7b26\u4e32\u7684<strong>\u524dn\u4e2a\u5b57\u7b26<\/strong>\u62fc\u63a5\u5230\u76ee\u6807\u5b57\u7b26\u4e32\u672b\u5c3e\uff0c\u5e76\u81ea\u52a8\u6dfb\u52a0<code>\\0<\/code>\u3002<\/td><td><code>char* dest<\/code>, <code>const char* src<\/code>, <code>size_t n<\/code><\/td><td>\u76ee\u6807\u5b57\u7b26\u4e32\u7684\u8d77\u59cb\u5730\u5740\uff08<code>char*<\/code>\uff09\u3002<\/td><td><strong>\u76f8\u5bf9\u5b89\u5168<\/strong>\u3002\u901a\u8fc7<code>n<\/code>\u9650\u5236\u6700\u5927\u6dfb\u52a0\u5b57\u7b26\u6570\uff0c\u4f46\u9700\u786e\u4fdd\u76ee\u6807\u6570\u7ec4\u6709<code>(\u539f\u957f\u5ea6 + n + 1)<\/code>\u7684\u7a7a\u95f4\u3002<\/td><\/tr><tr><td><strong><code>strcmp()<\/code><\/strong>\u200b<\/td><td><strong>\u6bd4\u8f83<\/strong>\u4e24\u4e2a\u5b57\u7b26\u4e32\u7684<strong>\u5185\u5bb9<\/strong>\u662f\u5426\u5b8c\u5168\u76f8\u540c\u3002<\/td><td><code>const char* str1<\/code>, <code>const char* str2<\/code><\/td><td>\u76f8\u7b49\u5219\u8fd4\u56de<strong>0<\/strong>\uff1b<br><code>str1<\/code>&lt;<code>str2<\/code>\u8fd4\u56de<strong>\u8d1f\u6574\u6570<\/strong>\uff1b<br><code>str1<\/code>&gt;<code>str2<\/code>\u8fd4\u56de<strong>\u6b63\u6574\u6570<\/strong>\u3002<\/td><td>\u6309\u5b57\u7b26\u7684ASCII\u7801\u9010\u5bf9\u6bd4\u8f83\uff0c\u76f4\u5230\u9047\u5230\u4e0d\u540c\u6216<code>\\0<\/code>\u3002C\u6807\u51c6<strong>\u4e0d\u4fdd\u8bc1<\/strong>\u8fd4\u56de\u5177\u4f53ASCII\u7801\u5dee\u503c\uff0c\u8bb8\u591a\u5b9e\u73b0\u53ea\u8fd4\u56de<code>-1<\/code>\uff0c<code>0<\/code>\uff0c<code>1<\/code>\u3002<\/td><\/tr><tr><td><strong><code>strncmp()<\/code><\/strong>\u200b<\/td><td>\u6bd4\u8f83\u4e24\u4e2a\u5b57\u7b26\u4e32\u7684<strong>\u524dn\u4e2a\u5b57\u7b26<\/strong>\u662f\u5426\u76f8\u540c\u3002<\/td><td><code>const char* str1<\/code>, <code>const char* str2<\/code>, <code>size_t n<\/code><\/td><td>\u6bd4\u8f83\u7ed3\u679c\uff0c\u89c4\u5219\u540c<code>strcmp()<\/code>\u3002<\/td><td>\u53ea\u6bd4\u8f83\u5230\u6307\u5b9a\u957f\u5ea6<code>n<\/code>\u6216\u9047\u5230<code>\\0<\/code>\u3002\u9002\u7528\u4e8e\u6bd4\u8f83\u5b57\u7b26\u4e32\u524d\u7f00\u3002<\/td><\/tr><tr><td><strong><code>strcpy()<\/code><\/strong>\u200b<\/td><td>\u5c06\u6e90\u5b57\u7b26\u4e32<strong>\u62f7\u8d1d<\/strong>\u5230\u76ee\u6807\u5730\u5740\uff08\u8986\u76d6\u76ee\u6807\uff09\u3002<\/td><td><code>char* dest<\/code>, <code>const char* src<\/code><\/td><td>\u76ee\u6807\u5b57\u7b26\u4e32\u7684\u8d77\u59cb\u5730\u5740\uff08<code>char*<\/code>\uff09\u3002<\/td><td><strong>\u4e0d\u5b89\u5168<\/strong>\u3002\u4e0d\u68c0\u67e5\u76ee\u6807\u6570\u7ec4\u7a7a\u95f4\uff0c\u53ef\u80fd\u5bfc\u81f4\u6ea2\u51fa\u3002\u76ee\u6807\u5730\u5740\u4e0d\u4e00\u5b9a\u662f\u6570\u7ec4\u5f00\u5934\uff08\u53ef\u6307\u5b9a\u504f\u79fb\u91cf\uff09\u3002<\/td><\/tr><tr><td><strong><code>strncpy()<\/code><\/strong>\u200b<\/td><td>\u5c06\u6e90\u5b57\u7b26\u4e32\u7684<strong>\u524dn\u4e2a\u5b57\u7b26<\/strong>\u62f7\u8d1d\u5230\u76ee\u6807\u5730\u5740\u3002\u82e5\u672a\u5230<code>n<\/code>\u5c31\u9047\u5230<code>\\0<\/code>\uff0c\u5269\u4f59\u90e8\u5206\u8865<code>\\0<\/code>\u3002<\/td><td><code>char* dest<\/code>, <code>const char* src<\/code>, <code>size_t n<\/code><\/td><td>\u76ee\u6807\u5b57\u7b26\u4e32\u7684\u8d77\u59cb\u5730\u5740\uff08<code>char*<\/code>\uff09\u3002<\/td><td><strong>\u76f8\u5bf9\u5b89\u5168<\/strong>\u3002\u901a\u8fc7<code>n<\/code>\u9650\u5236\u6700\u5927\u62f7\u8d1d\u6570\uff0c\u4f46\u4e0d\u4f1a\u81ea\u52a8\u5728\u672b\u5c3e\u6dfb\u52a0<code>\\0<\/code>\uff08\u9664\u975e<code>src<\/code>\u957f\u5ea6\u5c0f\u4e8e<code>n<\/code>\uff09\uff0c\u4f7f\u7528\u65f6\u9700\u8c28\u614e\u3002\u76ee\u6807\u5730\u5740\u53ef\u6307\u5b9a\u504f\u79fb\u3002<\/td><\/tr><tr><td><strong><code>sprintf()<\/code><\/strong>\u200b<\/td><td>\u5c06<strong>\u683c\u5f0f\u5316<\/strong>\u7684\u6570\u636e\u5199\u5165\u5b57\u7b26\u4e32\uff08\u800c\u975e\u5c4f\u5e55\uff09\u3002<\/td><td><code>char* str<\/code>, <code>const char* format, ...<\/code><\/td><td>\u6210\u529f\u65f6\u8fd4\u56de\u5199\u5165\u7684\u5b57\u7b26\u603b\u6570\uff08<code>int<\/code>\uff09\u3002<\/td><td>\u58f0\u660e\u5728<code>stdio.h<\/code>\u3002\u529f\u80fd\u5f3a\u5927\uff0c\u4f46<strong>\u4e0d\u5b89\u5168<\/strong>\uff0c\u4e0d\u68c0\u67e5\u76ee\u6807\u6570\u7ec4\u5927\u5c0f\uff0c\u6781\u6613\u5bfc\u81f4\u6ea2\u51fa\u3002\u5efa\u8bae\u4f7f\u7528\u66f4\u5b89\u5168\u7684<code>sprintf_s()<\/code>\uff08\u5982\u53ef\u7528\uff09\u3002<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">4.9 \u5176\u4ed6\u5b57\u7b26\u4e32\u51fd\u6570<\/h3>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>\u51fd\u6570\u540d<\/th><th>\u529f\u80fd\u63cf\u8ff0<\/th><th>\u53c2\u6570\u8bf4\u660e<\/th><th>\u8fd4\u56de\u503c<\/th><th>\u4e3b\u8981\u7279\u70b9\u4e0e\u6ce8\u610f\u4e8b\u9879<\/th><\/tr><\/thead><tbody><tr><td><strong><code>strchr()<\/code><\/strong>\u200b<\/td><td>\u5728\u5b57\u7b26\u4e32\u4e2d<strong>\u4ece\u5de6\u81f3\u53f3<\/strong>\u67e5\u627e<strong>\u7b2c\u4e00\u6b21<\/strong>\u51fa\u73b0\u7684\u6307\u5b9a\u5b57\u7b26\u3002<\/td><td><code>const char* str<\/code>, <code>int c<\/code>(\u8981\u67e5\u627e\u7684\u5b57\u7b26)<\/td><td>\u6307\u5411\u8be5\u5b57\u7b26\u7684<strong>\u6307\u9488<\/strong>\uff1b\u5982\u679c\u672a\u627e\u5230\uff0c\u5219\u8fd4\u56de <strong><code>NULL<\/code><\/strong>\u3002<\/td><td>\u67e5\u627e\u5305\u542b\u7ec8\u6b62\u7a7a\u5b57\u7b26 <code>\\0<\/code>\u5728\u5185\u7684\u5b57\u7b26\u3002\u5e38\u7528\u4e8e\u68c0\u67e5\u5b57\u7b26\u4e32\u4e2d\u662f\u5426\u5b58\u5728\u67d0\u4e2a\u5b57\u7b26\u6216\u5206\u5272\u5b57\u7b26\u4e32\u3002<\/td><\/tr><tr><td><strong><code>strrchr()<\/code><\/strong>\u200b<\/td><td>\u5728\u5b57\u7b26\u4e32\u4e2d<strong>\u4ece\u53f3\u81f3\u5de6<\/strong>\uff08\u53cd\u5411\uff09\u67e5\u627e<strong>\u6700\u540e\u4e00\u6b21<\/strong>\u51fa\u73b0\u7684\u6307\u5b9a\u5b57\u7b26\u3002<\/td><td><code>const char* str<\/code>, <code>int c<\/code><\/td><td>\u6307\u5411\u8be5\u5b57\u7b26\u6700\u540e\u51fa\u73b0\u4f4d\u7f6e\u7684<strong>\u6307\u9488<\/strong>\uff1b\u5982\u679c\u672a\u627e\u5230\uff0c\u8fd4\u56de <strong><code>NULL<\/code><\/strong>\u3002<\/td><td>\u5e38\u7528\u4e8e\u83b7\u53d6\u6587\u4ef6\u8def\u5f84\u4e2d\u7684\u6587\u4ef6\u540d\uff08\u67e5\u627e\u6700\u540e\u4e00\u4e2a<code>\/<\/code>\u6216<code>\\`\uff09\u6216\u6587\u4ef6\u6269\u5c55\u540d\uff08\u67e5\u627e\u6700\u540e\u4e00\u4e2a<\/code>.`\uff09\u3002<\/td><\/tr><tr><td><strong><code>strstr()<\/code><\/strong>\u200b<\/td><td>\u5728\u5b57\u7b26\u4e32\u4e2d\u67e5\u627e<strong>\u5b50\u5b57\u7b26\u4e32<\/strong>\u7684\u7b2c\u4e00\u6b21\u51fa\u73b0\u4f4d\u7f6e\u3002<\/td><td><code>const char* haystack<\/code>(\u88ab\u67e5\u627e\u5b57\u7b26\u4e32), <code>const char* needle<\/code>(\u8981\u67e5\u627e\u7684\u5b50\u4e32)<\/td><td>\u6307\u5411\u627e\u5230\u7684\u5b50\u4e32\u9996\u5b57\u7b26\u7684<strong>\u6307\u9488<\/strong>\uff1b\u5982\u679c\u672a\u627e\u5230\uff0c\u8fd4\u56de <strong><code>NULL<\/code><\/strong>\u3002<\/td><td>\u662f<strong>\u5b50\u4e32\u67e5\u627e<\/strong>\u7684\u6838\u5fc3\u51fd\u6570\u3002\u5982\u679c<code>needle<\/code>\u4e3a\u7a7a\u5b57\u7b26\u4e32\uff0c\u901a\u5e38\u8fd4\u56de<code>haystack<\/code>\u7684\u8d77\u59cb\u5730\u5740\u3002<\/td><\/tr><tr><td><strong><code>strspn()<\/code><\/strong>\u200b<\/td><td>\u8ba1\u7b97\u5b57\u7b26\u4e32<strong>\u8d77\u59cb\u90e8\u5206<\/strong>\u8fde\u7eed\u5305\u542b\u6307\u5b9a\u5b57\u7b26\u96c6\u4e2d\u5b57\u7b26\u7684<strong>\u6700\u5927\u957f\u5ea6<\/strong>\u3002<\/td><td><code>const char* str1<\/code>, <code>const char* str2<\/code>(\u63a5\u53d7\u7684\u5b57\u7b26\u96c6\u5408)<\/td><td>\u8fde\u7eed\u5339\u914d\u5b57\u7b26\u7684<strong>\u957f\u5ea6<\/strong>\uff08<code>size_t<\/code>\u7c7b\u578b\uff09\u3002<\/td><td>\u529f\u80fd\u662f\u201c<strong>\u626b\u63cf\u5e76\u8ba1\u6570\u5339\u914d\u7684\u5b57\u7b26<\/strong>\u201d\u3002\u5e38\u7528\u4e8e\u8df3\u8fc7\u524d\u7f00\u4e2d\u7684\u7279\u5b9a\u5b57\u7b26\uff08\u5982\u7a7a\u767d\u7b26\uff09\u3002<\/td><\/tr><tr><td><strong><code>strcspn()<\/code><\/strong>\u200b<\/td><td>\u8ba1\u7b97\u5b57\u7b26\u4e32<strong>\u8d77\u59cb\u90e8\u5206<\/strong>\u8fde\u7eed<strong>\u4e0d\u5305\u542b<\/strong>\u6307\u5b9a\u5b57\u7b26\u96c6\u4e2d\u4efb\u4f55\u5b57\u7b26\u7684<strong>\u6700\u5927\u957f\u5ea6<\/strong>\u3002<\/td><td><code>const char* str1<\/code>, <code>const char* str2<\/code>(\u62d2\u7edd\u7684\u5b57\u7b26\u96c6\u5408)<\/td><td>\u8fde\u7eed\u4e0d\u5339\u914d\u5b57\u7b26\u7684<strong>\u957f\u5ea6<\/strong>\uff08<code>size_t<\/code>\u7c7b\u578b\uff09\u3002<\/td><td>\u529f\u80fd\u662f\u201c<strong>\u626b\u63cf\u5e76\u8ba1\u6570\u4e0d\u5339\u914d\u7684\u5b57\u7b26<\/strong>\u201d\u3002\u662f<code>strspn()<\/code>\u7684\u4e92\u8865\u51fd\u6570\uff0c\u5e38\u7528\u4e8e\u67e5\u627e\u7b2c\u4e00\u4e2a\u5206\u9694\u7b26\u51fa\u73b0\u7684\u4f4d\u7f6e\u3002<\/td><\/tr><tr><td><strong><code>strpbrk()<\/code><\/strong>\u200b<\/td><td>\u5728\u5b57\u7b26\u4e32\u4e2d\u67e5\u627e<strong>\u4efb\u4f55\u4e00\u4e2a<\/strong>\u5c5e\u4e8e\u6307\u5b9a\u5b57\u7b26\u96c6\u7684\u5b57\u7b26\u7684<strong>\u7b2c\u4e00\u6b21<\/strong>\u51fa\u73b0\u4f4d\u7f6e\u3002<\/td><td><code>const char* str1<\/code>, <code>const char* str2<\/code>(\u8981\u641c\u7d22\u7684\u5b57\u7b26\u96c6\u5408)<\/td><td>\u6307\u5411\u627e\u5230\u7684\u5b57\u7b26\u7684<strong>\u6307\u9488<\/strong>\uff1b\u5982\u679c\u672a\u627e\u5230\uff0c\u8fd4\u56de <strong><code>NULL<\/code><\/strong>\u3002<\/td><td>\u529f\u80fd\u662f\u201c<strong>\u67e5\u627e\u6765\u81ea\u96c6\u5408\u7684\u4efb\u4f55\u4e00\u4e2a\u5b57\u7b26<\/strong>\u201d\u3002\u5e38\u7528\u4e8e\u67e5\u627e\u7b2c\u4e00\u4e2a\u5206\u9694\u7b26\uff08\u5982\u7a7a\u683c\u3001\u9017\u53f7\u7b49\uff09\u3002<\/td><\/tr><tr><td><strong><code>strtok()<\/code><\/strong>\u200b<\/td><td>\u6839\u636e\u4e00\u7ec4\u5206\u9694\u7b26\u5c06\u5b57\u7b26\u4e32<strong>\u5206\u5272<\/strong>\u6210\u4e00\u7cfb\u5217\u6807\u8bb0\uff08tokens\uff09\u3002<\/td><td><code>char* str<\/code>(\u5f85\u5206\u5272\u5b57\u7b26\u4e32\uff0c\u9996\u6b21\u8c03\u7528\u4f20\u5165)\uff0c <code>const char* delim<\/code>(\u5206\u9694\u7b26\u96c6\u5408)<\/td><td>\u6307\u5411\u4e0b\u4e00\u4e2a\u6807\u8bb0\u7684<strong>\u6307\u9488<\/strong>\uff1b\u5982\u679c\u6ca1\u6709\u66f4\u591a\u6807\u8bb0\uff0c\u8fd4\u56de <strong><code>NULL<\/code><\/strong>\u3002<\/td><td><strong>1. \u4f1a\u4fee\u6539\u539f\u5b57\u7b26\u4e32<\/strong>\uff0c\u7528<code>\\0<\/code>\u66ff\u6362\u5206\u9694\u7b26\u3002<br><strong>2. \u975e\u7ebf\u7a0b\u5b89\u5168<\/strong>\uff0c\u56e0\u4e3a\u5185\u90e8\u4f7f\u7528\u9759\u6001\u7f13\u51b2\u533a\u3002<br><strong>3. \u9996\u6b21\u8c03\u7528<\/strong>\u4f20\u5165\u5f85\u5206\u5272\u5b57\u7b26\u4e32\uff0c<strong>\u540e\u7eed\u8c03\u7528<\/strong>\u9700\u4f20\u5165<code>NULL<\/code>\u3002<\/td><\/tr><tr><td><strong><code>memcpy()<\/code><\/strong>\u200b<\/td><td>\u4ece\u6e90\u5185\u5b58\u5730\u5740<strong>\u62f7\u8d1d<\/strong>\u6307\u5b9a\u5b57\u8282\u6570\u7684\u6570\u636e\u5230\u76ee\u6807\u5730\u5740\u3002<\/td><td><code>void* dest<\/code>, <code>const void* src<\/code>, <code>size_t n<\/code>(\u5b57\u8282\u6570)<\/td><td>\u76ee\u6807\u5185\u5b58\u5730\u5740\uff08<code>dest<\/code>\uff09\u3002<\/td><td><strong>\u4e0d\u5904\u7406\u5185\u5b58\u91cd\u53e0<\/strong>\u3002\u5982\u679c\u6e90\u548c\u76ee\u6807\u5185\u5b58\u533a\u57df\u91cd\u53e0\uff0c\u884c\u4e3a\u662f<strong>\u672a\u5b9a\u4e49\u7684<\/strong>\u3002\u901a\u5e38\u7528\u4e8e\u62f7\u8d1d\u4e0d\u91cd\u53e0\u7684\u6570\u636e\u5757\uff0c\u6548\u7387\u9ad8\u3002<\/td><\/tr><tr><td><strong><code>memmove()<\/code><\/strong>\u200b<\/td><td>\u4ece\u6e90\u5185\u5b58\u5730\u5740<strong>\u62f7\u8d1d<\/strong>\u6307\u5b9a\u5b57\u8282\u6570\u7684\u6570\u636e\u5230\u76ee\u6807\u5730\u5740\u3002<\/td><td><code>void* dest<\/code>, <code>const void* src<\/code>, <code>size_t n<\/code>(\u5b57\u8282\u6570)<\/td><td>\u76ee\u6807\u5185\u5b58\u5730\u5740\uff08<code>dest<\/code>\uff09\u3002<\/td><td><strong>\u80fd\u6b63\u786e\u5904\u7406\u5185\u5b58\u91cd\u53e0<\/strong>\u3002\u5373\u4f7f<code>src<\/code>\u548c<code>dest<\/code>\u533a\u57df\u91cd\u53e0\uff0c\u4e5f\u80fd\u4fdd\u8bc1\u62f7\u8d1d\u7ed3\u679c\u6b63\u786e\u3002\u901a\u5e38\u6bd4<code>memcpy<\/code>\u7a0d\u6162\uff0c\u4f46\u66f4\u5b89\u5168\u3002<\/td><\/tr><tr><td><strong><code>memset()<\/code><\/strong>\u200b<\/td><td>\u5c06\u5185\u5b58\u533a\u57df\u7684\u6bcf\u4e2a\u5b57\u8282\u8bbe\u7f6e\u4e3a\u6307\u5b9a\u7684\u503c\u3002<\/td><td><code>void* ptr<\/code>, <code>int value<\/code>, <code>size_t n<\/code>(\u5b57\u8282\u6570)<\/td><td>\u5185\u5b58\u533a\u57df\u8d77\u59cb\u5730\u5740\uff08<code>ptr<\/code>\uff09\u3002<\/td><td>\u5e38\u7528\u4e8e<strong>\u5185\u5b58\u521d\u59cb\u5316<\/strong>\uff08\u5982\u6570\u7ec4\u6e05\u96f6 <code>memset(arr, 0, sizeof(arr))<\/code>\uff09\u6216\u4e3a\u5b57\u7b26\u4e32\u6570\u7ec4\u586b\u5145\u7279\u5b9a\u5b57\u7b26\u3002<\/td><\/tr><tr><td><strong><code>memcmp()<\/code><\/strong>\u200b<\/td><td>\u6bd4\u8f83\u4e24\u4e2a\u5185\u5b58\u533a\u57df\u7684<strong>\u524dn\u4e2a\u5b57\u8282<\/strong>\u3002<\/td><td><code>const void* ptr1<\/code>, <code>const void* ptr2<\/code>, <code>size_t n<\/code>(\u5b57\u8282\u6570)<\/td><td>\u540c<code>strcmp()<\/code>\uff1a\u76f8\u7b49\u8fd4\u56de<strong>0<\/strong>\uff1b<code>ptr1<\/code>&lt;<code>ptr2<\/code>\u8fd4\u56de<strong>\u8d1f\u6574\u6570<\/strong>\uff1b<code>ptr1<\/code>&gt;<code>ptr2<\/code>\u8fd4\u56de<strong>\u6b63\u6574\u6570<\/strong>\u3002<\/td><td>\u6309<strong>\u5b57\u8282<\/strong>\u9010\u4f4d\u6bd4\u8f83\uff0c\u53ef\u7528\u4e8e\u6bd4\u8f83\u4efb\u610f\u6570\u636e\u7c7b\u578b\uff08\u7ed3\u6784\u4f53\u3001\u6570\u7ec4\u7b49\uff09\uff0c\u4e0d\u4ec5\u9650\u4e8e\u5b57\u7b26\u4e32\u3002<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">5. \u547d\u4ee4\u884c\u53c2\u6570<\/h2>\n\n\n\n<p>C\u7f16\u8bd1\u5668\u5141\u8bb8<code>main()<\/code>\u51fd\u6570\u6ca1\u6709\u53c2\u6570\u6216\u67092\u4e2a\u53c2\u6570\u3002\u5f53<code>main()<\/code>\u51fd\u6570\u6709\u4e24\u4e2a\u53c2\u6570\u662f\uff0c\u7b2c1\u4e2a\u53c2\u6570\u4e3a\u547d\u4ee4\u884c\u4e2d\u7684\u5b57\u7b26\u4e32\u6570\u91cf\uff0c\u7b2c2\u4e2a\u53c2\u6570\u662f\u5b57\u7b26\u4e32\u6570\u7ec4\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#include &lt;stdio.h&gt;\n\nint main(int argc, char *argv&#91;]) {\n\tfor (int i = 1; i &lt; argc; i++) {\n\t\tprintf(\"argv&#91;%d]: %s\\n\", i, argv&#91;i]);\n\t}\n\treturn 0;\n}\n<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>E:\\Documents\\_005projects\\C\u7ec3\u4e60\u9879\u76ee\\day10\\x64\\Debug&gt;day10.exe arg1 arg2 arg3\nargv&#91;0]: day10.exe\nargv&#91;1]: arg1\nargv&#91;2]: arg2\nargv&#91;3]: arg3\n<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>C:\\Users\\admin&gt;E:\\Documents\\_005projects\\C\u7ec3\u4e60\u9879\u76ee\\day10\\x64\\Debug\\day10.exe arg1 arg2 arg3\nargv&#91;0]: E:\\Documents\\_005projects\\C\u7ec3\u4e60\u9879\u76ee\\day10\\x64\\Debug\\day10.exe\nargv&#91;1]: arg1\nargv&#91;2]: arg2\nargv&#91;3]: arg3\n<\/code><\/pre>\n\n\n\n<p>\u26a0\ufe0f<strong>\u6ce8\u610f<\/strong>\uff1a\u6709\u4e9b\u7cfb\u7edf\u4f1a\u628a\u7a0b\u5e8f\u672c\u8eab\u540d\u79f0\u8d4b\u7ed9<code>argv[0]<\/code>\uff0c\u4f46\u6709\u4e9b\u7cfb\u7edf\u4e0d\u4f1a\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">6. \u5c06\u6570\u5b57\u5b57\u7b26\u8f6c\u6362\u4e3a\u6570\u5b57<\/h2>\n\n\n\n<p>\u4f7f\u7528\u5b9a\u4e49\u5728<code>stdlib.h<\/code>\u5934\u6587\u4ef6\u4e2d\u7684<code>atoi()<\/code>\u51fd\u6570\u53ef\u4ee5\u5c06\u6570\u5b57\u5b57\u7b26\u4e32\u8f6c\u6362\u4e3a\u6570\u5b57\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#include &lt;stdio.h&gt;\n#include &lt;stdlib.h&gt;\n\nint main() {\n\tprintf(\"%d\\n\", atoi(\"12\"));\n\tprintf(\"%.2f\\n\", atoi(\"12.13\"));\n\tprintf(\"%d\\n\", atoi(\"12abc\"));\n\tprintf(\"%d\\n\", atoi(\"abc12\"));\n\tprintf(\"%d\\n\", atoi(\"Hello\"));\n\treturn 0;\n}\n\/\/\u5b9e\u9645\u8f93\u51fa\n\/\/12\n\/\/0.00\n\/\/12\n\/\/0\n\/\/0\n<\/code><\/pre>\n\n\n\n<p><code>atoi()<\/code>\u51fd\u6570\u53ea\u80fd\u5904\u7406\u6574\u6570\u5f00\u5934\u7684\u5b57\u7b26\u4e32\uff0c\u5bf9\u4e8e\u4e0d\u80fd\u5904\u7406\u7684\u60c5\u51b5\uff0cC\u6807\u51c6\u89c4\u5b9a\u6b64\u79cd\u884c\u4e3a\u7684\u7ed3\u679c\u662f\u672a\u5b9a\u4e49\u7684\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>1. \u8868\u793a\u5b57\u7b26\u4e32\u548c\u5b57\u7b26\u4e32I\/O \u5b57\u7b26\u4e32\u662f\u4ee5\u7a7a\u5b57\u7b26\uff08\\0\uff09\u7ed3\u5c3e\u7684char\u7c7b\u578b\u6570\u7ec4\u3002 1.1 \u5728\u7a0b\u5e8f\u4e2d\u5b9a\u4e49\u5b57\u7b26\u4e32  [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10],"tags":[11],"class_list":["post-110","post","type-post","status-publish","format-standard","hentry","category-c-2","tag-c-2"],"_links":{"self":[{"href":"https:\/\/www.caldm.cn\/index.php\/wp-json\/wp\/v2\/posts\/110","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.caldm.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.caldm.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.caldm.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.caldm.cn\/index.php\/wp-json\/wp\/v2\/comments?post=110"}],"version-history":[{"count":1,"href":"https:\/\/www.caldm.cn\/index.php\/wp-json\/wp\/v2\/posts\/110\/revisions"}],"predecessor-version":[{"id":111,"href":"https:\/\/www.caldm.cn\/index.php\/wp-json\/wp\/v2\/posts\/110\/revisions\/111"}],"wp:attachment":[{"href":"https:\/\/www.caldm.cn\/index.php\/wp-json\/wp\/v2\/media?parent=110"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.caldm.cn\/index.php\/wp-json\/wp\/v2\/categories?post=110"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.caldm.cn\/index.php\/wp-json\/wp\/v2\/tags?post=110"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}