{"id":72970,"date":"2026-02-06T20:49:24","date_gmt":"2026-02-06T12:49:24","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/72970.html"},"modified":"2026-02-06T20:49:24","modified_gmt":"2026-02-06T12:49:24","slug":"linux%e8%bd%af%e4%bb%b6%e7%bc%96%e7%a8%8b%ef%bc%9aio%e7%bc%96%e7%a8%8b%ef%bc%881%ef%bc%89","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/72970.html","title":{"rendered":"Linux\u8f6f\u4ef6\u7f16\u7a0b\uff1aIO\u7f16\u7a0b\uff081\uff09"},"content":{"rendered":"<h3>&#x1f4d8; \u4e00\u3001Linux IO\u7f16\u7a0b\u6838\u5fc3\u6982\u5ff5<\/h3>\n<h4>1.1 &#034;\u4e00\u5207\u7686\u662f\u6587\u4ef6&#034;\u7684\u7406\u5ff5<\/h4>\n<p>\u5728Linux\u7cfb\u7edf\u4e2d&#xff0c;\u6240\u6709\u8f93\u5165\u8f93\u51fa\u64cd\u4f5c\u90fd\u7edf\u4e00\u4e3a\u6587\u4ef6\u64cd\u4f5c&#xff0c;\u5177\u4f53\u5206\u4e3a\u4ee5\u4e0b\u51e0\u7c7b&#xff1a;<\/p>\n<table>\n<tr>\u6587\u4ef6\u7c7b\u578b\u6807\u8bc6\u7b26\u8bf4\u660e\u5178\u578b\u8bbe\u5907<\/tr>\n<tbody>\n<tr>\n<td>\u5757\u8bbe\u5907\u6587\u4ef6<\/td>\n<td>b<\/td>\n<td>\u6309\u5757\u8bbf\u95ee\u7684\u5b58\u50a8\u8bbe\u5907<\/td>\n<td>\u786c\u76d8\u3001U\u76d8<\/td>\n<\/tr>\n<tr>\n<td>\u5b57\u7b26\u8bbe\u5907\u6587\u4ef6<\/td>\n<td>c<\/td>\n<td>\u6309\u5b57\u7b26\u8bbf\u95ee\u7684\u8bbe\u5907<\/td>\n<td>\u952e\u76d8\u3001\u9f20\u6807\u3001\u7ec8\u7aef<\/td>\n<\/tr>\n<tr>\n<td>\u76ee\u5f55\u6587\u4ef6<\/td>\n<td>d<\/td>\n<td>\u5b58\u50a8\u6587\u4ef6\u4fe1\u606f\u7684\u5bb9\u5668<\/td>\n<td>\u6587\u4ef6\u5939<\/td>\n<\/tr>\n<tr>\n<td>\u666e\u901a\u6587\u4ef6<\/td>\n<td>&#8211;<\/td>\n<td>\u5e38\u89c4\u6570\u636e\u6587\u4ef6<\/td>\n<td>\u6587\u672c\u3001\u4e8c\u8fdb\u5236\u6587\u4ef6<\/td>\n<\/tr>\n<tr>\n<td>\u94fe\u63a5\u6587\u4ef6<\/td>\n<td>l<\/td>\n<td>\u6307\u5411\u5176\u4ed6\u6587\u4ef6\u7684\u5feb\u6377\u65b9\u5f0f<\/td>\n<td>\u7b26\u53f7\u94fe\u63a5\u3001\u786c\u94fe\u63a5<\/td>\n<\/tr>\n<tr>\n<td>\u5957\u63a5\u5b57\u6587\u4ef6<\/td>\n<td>s<\/td>\n<td>\u8fdb\u7a0b\u95f4\u901a\u4fe1\u6587\u4ef6<\/td>\n<td>\u7f51\u7edcsocket<\/td>\n<\/tr>\n<tr>\n<td>\u7ba1\u9053\u6587\u4ef6<\/td>\n<td>p<\/td>\n<td>\u8fdb\u7a0b\u95f4\u901a\u4fe1\u6587\u4ef6<\/td>\n<td>\u533f\u540d\/\u547d\u540d\u7ba1\u9053<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h4>1.2 IO\u64cd\u4f5c\u7684\u7edf\u4e00\u6027<\/h4>\n<p>\u6838\u5fc3\u601d\u60f3&#xff1a;\u65e0\u8bba\u64cd\u4f5c\u4ec0\u4e48\u7c7b\u578b\u7684&#034;\u6587\u4ef6&#034;&#xff0c;\u90fd\u4f7f\u7528\u76f8\u4f3c\u7684IO\u63a5\u53e3\u3002<\/p>\n<h4>1.3 IO\u63a5\u53e3\u5206\u7c7b\u4f53\u7cfb<\/h4>\n<p>c<\/p>\n<p>Linux IO\u7cfb\u7edf<br \/>\n\u251c\u2500\u2500 \u6807\u51c6IO&#xff08;\u5e26\u7f13\u5b58&#xff09;<br \/>\n\u2502   \u251c\u2500\u2500 \u9002\u7528\u4e8e&#xff1a;\u666e\u901a\u6587\u4ef6<br \/>\n\u2502   \u251c\u2500\u2500 \u7279\u70b9&#xff1a;\u9ad8\u6548\u3001\u5e26\u7f13\u51b2\u673a\u5236<br \/>\n\u2502   \u2514\u2500\u2500 \u5934\u6587\u4ef6&#xff1a;#include &lt;stdio.h&gt;<br \/>\n\u2502<br \/>\n\u251c\u2500\u2500 \u6587\u4ef6IO&#xff08;\u65e0\u7f13\u5b58&#xff09;<br \/>\n\u2502   \u251c\u2500\u2500 \u9002\u7528\u4e8e&#xff1a;\u8bbe\u5907\u6587\u4ef6\u3001\u901a\u4fe1\u6587\u4ef6<br \/>\n\u2502   \u251c\u2500\u2500 \u7279\u70b9&#xff1a;\u76f4\u63a5\u3001\u5b9e\u65f6<br \/>\n\u2502   \u2514\u2500\u2500 \u5934\u6587\u4ef6&#xff1a;#include &lt;unistd.h&gt;\u3001#include &lt;fcntl.h&gt;<br \/>\n\u2502<br \/>\n\u2514\u2500\u2500 \u76ee\u5f55IO<br \/>\n    \u251c\u2500\u2500 \u9002\u7528\u4e8e&#xff1a;\u76ee\u5f55\u6587\u4ef6<br \/>\n    \u2514\u2500\u2500 \u51fd\u6570&#xff1a;opendir()\u3001readdir()\u3001closedir()<\/p>\n<h3>&#x1f4c2; \u4e8c\u3001\u6807\u51c6IO\u8be6\u7ec6\u89e3\u6790<\/h3>\n<h4>2.1 \u6807\u51c6IO\u7684\u57fa\u672c\u7279\u6027<\/h4>\n<h5>2.1.1 \u6587\u4ef6\u7c7b\u578b\u533a\u5206<\/h5>\n<ul>\n<li>\n<p>ASCII\u7801\u6587\u4ef6&#xff1a;\u5185\u5bb9\u4e3a\u53ef\u663e\u793a\u7684ASCII\u5b57\u7b26<\/p>\n<ul>\n<li>\n<p>\u793a\u4f8b&#xff1a;\u4ee3\u7801\u6587\u4ef6\u3001\u914d\u7f6e\u6587\u4ef6\u3001\u65e5\u5fd7\u6587\u4ef6<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u4e8c\u8fdb\u5236\u6587\u4ef6&#xff1a;\u5b58\u50a8\u4e8c\u8fdb\u5236\u6570\u636e<\/p>\n<ul>\n<li>\n<p>\u793a\u4f8b&#xff1a;\u56fe\u7247\u3001\u97f3\u9891\u3001\u89c6\u9891\u3001\u538b\u7f29\u5305<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u6ce8\u610f&#xff1a;ASCII\u6587\u4ef6\u662f\u4e8c\u8fdb\u5236\u6587\u4ef6\u7684\u7279\u6b8a\u5f62\u5f0f<\/p>\n<\/li>\n<\/ul>\n<h5>2.1.2 \u6807\u51c6IO\u64cd\u4f5c\u6d41\u7a0b<\/h5>\n<p>text<\/p>\n<p>\u6253\u5f00\u6587\u4ef6 (fopen)<br \/>\n    \u2193<br \/>\n\u8bfb\u5199\u64cd\u4f5c (\u591a\u79cd\u51fd\u6570)<br \/>\n    \u2193<br \/>\n\u5173\u95ed\u6587\u4ef6 (fclose)<\/p>\n<h4>2.2 \u9ed8\u8ba4\u6253\u5f00\u7684\u6d41&#xff08;\u9884\u5b9a\u4e49\u6587\u4ef6\u6307\u9488&#xff09;<\/h4>\n<table>\n<tr>\u6d41\u540d\u79f0\u6587\u4ef6\u6307\u9488\u6587\u4ef6\u63cf\u8ff0\u7b26\u7f13\u5b58\u7c7b\u578b\u7528\u9014<\/tr>\n<tbody>\n<tr>\n<td>\u6807\u51c6\u8f93\u5165<\/td>\n<td>stdin<\/td>\n<td>0<\/td>\n<td>\u884c\u7f13\u5b58<\/td>\n<td>\u952e\u76d8\u8f93\u5165<\/td>\n<\/tr>\n<tr>\n<td>\u6807\u51c6\u8f93\u51fa<\/td>\n<td>stdout<\/td>\n<td>1<\/td>\n<td>\u884c\u7f13\u5b58<\/td>\n<td>\u5c4f\u5e55\u8f93\u51fa<\/td>\n<\/tr>\n<tr>\n<td>\u6807\u51c6\u9519\u8bef<\/td>\n<td>stderr<\/td>\n<td>2<\/td>\n<td>\u65e0\u7f13\u5b58<\/td>\n<td>\u9519\u8bef\u8f93\u51fa<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h4>2.3 \u7f13\u5b58\u673a\u5236\u8be6\u89e3<\/h4>\n<h5>2.3.1 \u5168\u7f13\u5b58&#xff08;Full Buffering&#xff09;<\/h5>\n<ul>\n<li>\n<p>\u7f13\u5b58\u5927\u5c0f&#xff1a;4096\u5b57\u8282&#xff08;4KB&#xff09;<\/p>\n<\/li>\n<li>\n<p>\u5237\u65b0\u6761\u4ef6&#xff1a;<\/p>\n<li>\n<p>\u7f13\u5b58\u533a\u6ee1\u65f6\u81ea\u52a8\u5237\u65b0<\/p>\n<\/li>\n<li>\n<p>\u8c03\u7528fflush()\u51fd\u6570\u5f3a\u5236\u5237\u65b0<\/p>\n<\/li>\n<li>\n<p>\u7a0b\u5e8f\u6b63\u5e38\u7ed3\u675f\u65f6\u81ea\u52a8\u5237\u65b0<\/p>\n<\/li>\n<li>\n<p>\u8c03\u7528fclose()\u5173\u95ed\u6587\u4ef6\u65f6<\/p>\n<\/li>\n<\/li>\n<li>\n<p>\u5e94\u7528\u573a\u666f&#xff1a;\u666e\u901a\u6587\u4ef6\u64cd\u4f5c<\/p>\n<\/li>\n<\/ul>\n<h5>2.3.2 \u884c\u7f13\u5b58&#xff08;Line Buffering&#xff09;<\/h5>\n<ul>\n<li>\n<p>\u7f13\u5b58\u5927\u5c0f&#xff1a;1024\u5b57\u8282&#xff08;1KB&#xff09;<\/p>\n<\/li>\n<li>\n<p>\u5237\u65b0\u6761\u4ef6&#xff1a;<\/p>\n<li>\n<p>\u9047\u5230\u6362\u884c\u7b26\\\\n\u65f6\u5237\u65b0<\/p>\n<\/li>\n<li>\n<p>\u7f13\u5b58\u533a\u6ee1\u65f6\u5237\u65b0<\/p>\n<\/li>\n<li>\n<p>\u8c03\u7528fflush()\u51fd\u6570\u5f3a\u5236\u5237\u65b0<\/p>\n<\/li>\n<li>\n<p>\u7a0b\u5e8f\u6b63\u5e38\u7ed3\u675f<\/p>\n<\/li>\n<\/li>\n<li>\n<p>\u5e94\u7528\u573a\u666f&#xff1a;\u7ec8\u7aef\u8f93\u5165\u8f93\u51fa&#xff08;stdin\/stdout&#xff09;<\/p>\n<\/li>\n<\/ul>\n<h5>2.3.3 \u65e0\u7f13\u5b58&#xff08;Unbuffered&#xff09;<\/h5>\n<ul>\n<li>\n<p>\u7f13\u5b58\u5927\u5c0f&#xff1a;0\u5b57\u8282<\/p>\n<\/li>\n<li>\n<p>\u7279\u70b9&#xff1a;\u7acb\u5373\u8f93\u51fa&#xff0c;\u4e0d\u7f13\u5b58<\/p>\n<\/li>\n<li>\n<p>\u5e94\u7528\u573a\u666f&#xff1a;\u9519\u8bef\u8f93\u51fa&#xff08;stderr&#xff09;\u3001\u5b9e\u65f6\u65e5\u5fd7<\/p>\n<\/li>\n<\/ul>\n<h4>2.4 \u6807\u51c6IO\u51fd\u6570\u5168\u96c6&#xff08;\u8be6\u7ec6\u53c2\u6570\u8bf4\u660e&#xff09;<\/h4>\n<h5>2.4.1 \u6587\u4ef6\u6253\u5f00\/\u5173\u95ed\u51fd\u6570<\/h5>\n<p>fopen() \u51fd\u6570<\/p>\n<p>c<\/p>\n<p>\/**<br \/>\n * \u529f\u80fd&#xff1a;\u6253\u5f00\u6587\u4ef6\u5e76\u5efa\u7acb\u6d41<br \/>\n * \u53c2\u6570&#xff1a;<br \/>\n *   pathname&#xff1a;\u6587\u4ef6\u8def\u5f84<br \/>\n *   mode&#xff1a;\u6253\u5f00\u6a21\u5f0f<br \/>\n * \u8fd4\u56de\u503c&#xff1a;<br \/>\n *   \u6210\u529f&#xff1a;FILE* \u6307\u9488<br \/>\n *   \u5931\u8d25&#xff1a;NULL<br \/>\n *\/<br \/>\nFILE *fopen(const char *pathname, const char *mode);<\/p>\n<p>mode\u53c2\u6570\u8be6\u7ec6\u8bf4\u660e&#xff1a;<\/p>\n<table>\n<tr>\u6a21\u5f0f\u542b\u4e49\u6587\u4ef6\u4e0d\u5b58\u5728\u65f6\u6587\u4ef6\u5b58\u5728\u65f6\u521d\u59cb\u4f4d\u7f6e<\/tr>\n<tbody>\n<tr>\n<td>&#034;r&#034;<\/td>\n<td>\u53ea\u8bfb<\/td>\n<td>\u8fd4\u56deNULL<\/td>\n<td>\u6253\u5f00\u6210\u529f<\/td>\n<td>\u6587\u4ef6\u5f00\u5934<\/td>\n<\/tr>\n<tr>\n<td>&#034;r&#043;&#034;<\/td>\n<td>\u8bfb\u5199<\/td>\n<td>\u8fd4\u56deNULL<\/td>\n<td>\u6253\u5f00\u6210\u529f<\/td>\n<td>\u6587\u4ef6\u5f00\u5934<\/td>\n<\/tr>\n<tr>\n<td>&#034;w&#034;<\/td>\n<td>\u53ea\u5199<\/td>\n<td>\u521b\u5efa\u65b0\u6587\u4ef6<\/td>\n<td>\u6e05\u7a7a\u5185\u5bb9<\/td>\n<td>\u6587\u4ef6\u5f00\u5934<\/td>\n<\/tr>\n<tr>\n<td>&#034;w&#043;&#034;<\/td>\n<td>\u5199\u8bfb<\/td>\n<td>\u521b\u5efa\u65b0\u6587\u4ef6<\/td>\n<td>\u6e05\u7a7a\u5185\u5bb9<\/td>\n<td>\u6587\u4ef6\u5f00\u5934<\/td>\n<\/tr>\n<tr>\n<td>&#034;a&#034;<\/td>\n<td>\u8ffd\u52a0\u53ea\u5199<\/td>\n<td>\u521b\u5efa\u65b0\u6587\u4ef6<\/td>\n<td>\u4fdd\u7559\u5185\u5bb9<\/td>\n<td>\u6587\u4ef6\u672b\u5c3e<\/td>\n<\/tr>\n<tr>\n<td>&#034;a&#043;&#034;<\/td>\n<td>\u8ffd\u52a0\u8bfb\u5199<\/td>\n<td>\u521b\u5efa\u65b0\u6587\u4ef6<\/td>\n<td>\u4fdd\u7559\u5185\u5bb9<\/td>\n<td>\u6587\u4ef6\u672b\u5c3e<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>fclose() \u51fd\u6570<\/p>\n<p>c<\/p>\n<p>\/**<br \/>\n * \u529f\u80fd&#xff1a;\u5173\u95ed\u6587\u4ef6\u6d41<br \/>\n * \u53c2\u6570&#xff1a;<br \/>\n *   stream&#xff1a;\u8981\u5173\u95ed\u7684\u6587\u4ef6\u6d41\u6307\u9488<br \/>\n * \u8fd4\u56de\u503c&#xff1a;<br \/>\n *   \u6210\u529f&#xff1a;0<br \/>\n *   \u5931\u8d25&#xff1a;EOF(-1)<br \/>\n *\/<br \/>\nint fclose(FILE *stream);<\/p>\n<h5>2.4.2 \u5b57\u7b26\u8f93\u5165\u8f93\u51fa\u51fd\u6570<\/h5>\n<p>fputc() \u51fd\u6570<\/p>\n<p>c<\/p>\n<p>\/**<br \/>\n * \u529f\u80fd&#xff1a;\u5411\u6d41\u4e2d\u5199\u5165\u4e00\u4e2a\u5b57\u7b26<br \/>\n * \u53c2\u6570&#xff1a;<br \/>\n *   c&#xff1a;\u8981\u5199\u5165\u7684\u5b57\u7b26&#xff08;ASCII\u7801\u503c&#xff09;<br \/>\n *   stream&#xff1a;\u76ee\u6807\u6587\u4ef6\u6d41<br \/>\n * \u8fd4\u56de\u503c&#xff1a;<br \/>\n *   \u6210\u529f&#xff1a;\u5199\u5165\u5b57\u7b26\u7684ASCII\u7801\u503c<br \/>\n *   \u5931\u8d25&#xff1a;EOF(-1)<br \/>\n *\/<br \/>\nint fputc(int c, FILE *stream);<\/p>\n<p>\/\/ \u7b49\u4ef7\u5173\u7cfb<br \/>\nputchar(ch)  \u21d4  fputc(ch, stdout)<\/p>\n<p>fgetc() \u51fd\u6570<\/p>\n<p>c<\/p>\n<p>\/**<br \/>\n * \u529f\u80fd&#xff1a;\u4ece\u6d41\u4e2d\u8bfb\u53d6\u4e00\u4e2a\u5b57\u7b26<br \/>\n * \u53c2\u6570&#xff1a;<br \/>\n *   stream&#xff1a;\u6e90\u6587\u4ef6\u6d41<br \/>\n * \u8fd4\u56de\u503c&#xff1a;<br \/>\n *   \u6210\u529f&#xff1a;\u8bfb\u53d6\u5b57\u7b26\u7684ASCII\u7801\u503c<br \/>\n *   \u5931\u8d25\/\u6587\u4ef6\u7ed3\u675f&#xff1a;EOF(-1)<br \/>\n *\/<br \/>\nint fgetc(FILE *stream);<\/p>\n<p>\/\/ \u7b49\u4ef7\u5173\u7cfb<br \/>\nch &#061; getchar()  \u21d4  ch &#061; fgetc(stdin)<\/p>\n<h5>2.4.3 \u5b57\u7b26\u4e32\u8f93\u5165\u8f93\u51fa\u51fd\u6570<\/h5>\n<p>fputs() \u51fd\u6570<\/p>\n<p>c<\/p>\n<p>\/**<br \/>\n * \u529f\u80fd&#xff1a;\u5411\u6d41\u4e2d\u5199\u5165\u5b57\u7b26\u4e32<br \/>\n * \u53c2\u6570&#xff1a;<br \/>\n *   s&#xff1a;\u8981\u5199\u5165\u7684\u5b57\u7b26\u4e32&#xff08;\u4ee5&#039;\\\\0&#039;\u7ed3\u5c3e&#xff09;<br \/>\n *   stream&#xff1a;\u76ee\u6807\u6587\u4ef6\u6d41<br \/>\n * \u8fd4\u56de\u503c&#xff1a;<br \/>\n *   \u6210\u529f&#xff1a;\u975e\u8d1f\u6574\u6570<br \/>\n *   \u5931\u8d25&#xff1a;EOF(-1)<br \/>\n *\/<br \/>\nint fputs(const char *s, FILE *stream);<\/p>\n<p>fgets() \u51fd\u6570<\/p>\n<p>c<\/p>\n<p>\/**<br \/>\n * \u529f\u80fd&#xff1a;\u4ece\u6d41\u4e2d\u8bfb\u53d6\u5b57\u7b26\u4e32<br \/>\n * \u53c2\u6570&#xff1a;<br \/>\n *   s&#xff1a;\u5b58\u50a8\u8bfb\u53d6\u7ed3\u679c\u7684\u7f13\u51b2\u533a<br \/>\n *   size&#xff1a;\u6700\u591a\u8bfb\u53d6\u7684\u5b57\u7b26\u6570&#xff08;\u5305\u62ec\u7ed3\u5c3e\u7684&#039;\\\\0&#039;&#xff09;<br \/>\n *   stream&#xff1a;\u6e90\u6587\u4ef6\u6d41<br \/>\n * \u8fd4\u56de\u503c&#xff1a;<br \/>\n *   \u6210\u529f&#xff1a;\u7f13\u51b2\u533a\u5730\u5740s<br \/>\n *   \u5931\u8d25\/\u6587\u4ef6\u7ed3\u675f&#xff1a;NULL<br \/>\n *\/<br \/>\nchar *fgets(char *s, int size, FILE *stream);<\/p>\n<p>\u91cd\u8981\u533a\u522b\u8bf4\u660e&#xff1a;<\/p>\n<p>c<\/p>\n<p>\/\/ fgets vs gets<br \/>\nchar str[100];<br \/>\nfgets(str, sizeof(str), stdin);  \/\/ \u4fdd\u7559\u6362\u884c\u7b26&#039;\\\\n&#039;<br \/>\ngets(str);                       \/\/ \u4e0d\u4fdd\u7559\u6362\u884c\u7b26<\/p>\n<p>\/\/ \u4f7f\u7528fgets\u6a21\u62dfgets\u7684\u529f\u80fd<br \/>\nfgets(str, sizeof(str), stdin);<br \/>\nstr[strlen(str) &#8211; 1] &#061; &#039;\\\\0&#039;;     \/\/ \u53bb\u6389\u6362\u884c\u7b26<\/p>\n<p>\/\/ fputs vs puts<br \/>\nfputs(&#034;Hello&#034;, stdout);  \/\/ \u4e0d\u6dfb\u52a0\u6362\u884c\u7b26<br \/>\nputs(&#034;Hello&#034;);          \/\/ \u81ea\u52a8\u6dfb\u52a0\u6362\u884c\u7b26<\/p>\n<h5>2.4.4 \u683c\u5f0f\u5316\u8f93\u5165\u8f93\u51fa\u51fd\u6570<\/h5>\n<p>fprintf() \u51fd\u6570<\/p>\n<p>c<\/p>\n<p>\/**<br \/>\n * \u529f\u80fd&#xff1a;\u5411\u6d41\u4e2d\u5199\u5165\u683c\u5f0f\u5316\u5b57\u7b26\u4e32<br \/>\n * \u53c2\u6570&#xff1a;<br \/>\n *   stream&#xff1a;\u76ee\u6807\u6587\u4ef6\u6d41<br \/>\n *   format&#xff1a;\u683c\u5f0f\u5316\u5b57\u7b26\u4e32<br \/>\n *   &#8230;&#xff1a;\u53ef\u53d8\u53c2\u6570&#xff08;\u8981\u8f93\u51fa\u7684\u53d8\u91cf&#xff09;<br \/>\n * \u8fd4\u56de\u503c&#xff1a;<br \/>\n *   \u6210\u529f&#xff1a;\u8f93\u51fa\u7684\u5b57\u7b26\u6570<br \/>\n *   \u5931\u8d25&#xff1a;\u8d1f\u6570<br \/>\n *\/<br \/>\nint fprintf(FILE *stream, const char *format, &#8230;);<\/p>\n<p>\/\/ \u793a\u4f8b<br \/>\nfprintf(stdout, &#034;Name: %s, Age: %d\\\\n&#034;, name, age);<br \/>\nfprintf(file, &#034;Data: %f, %f, %f\\\\n&#034;, x, y, z);<\/p>\n<p>fscanf() \u51fd\u6570<\/p>\n<p>c<\/p>\n<p>\/**<br \/>\n * \u529f\u80fd&#xff1a;\u4ece\u6d41\u4e2d\u8bfb\u53d6\u683c\u5f0f\u5316\u6570\u636e<br \/>\n * \u53c2\u6570&#xff1a;<br \/>\n *   stream&#xff1a;\u6e90\u6587\u4ef6\u6d41<br \/>\n *   format&#xff1a;\u683c\u5f0f\u5316\u5b57\u7b26\u4e32<br \/>\n *   &#8230;&#xff1a;\u53ef\u53d8\u53c2\u6570&#xff08;\u5b58\u50a8\u8bfb\u53d6\u7ed3\u679c\u7684\u53d8\u91cf\u5730\u5740&#xff09;<br \/>\n * \u8fd4\u56de\u503c&#xff1a;<br \/>\n *   \u6210\u529f&#xff1a;\u6210\u529f\u5339\u914d\u5e76\u8d4b\u503c\u7684\u53c2\u6570\u4e2a\u6570<br \/>\n *   \u5931\u8d25\/\u6587\u4ef6\u7ed3\u675f&#xff1a;EOF(-1)<br \/>\n *\/<br \/>\nint fscanf(FILE *stream, const char *format, &#8230;);<\/p>\n<p>\/\/ \u793a\u4f8b<br \/>\nint count &#061; fscanf(file, &#034;%d %s %f&#034;, &amp;id, name, &amp;score);<\/p>\n<h4>2.5 \u6587\u4ef6\u64cd\u4f5c\u5b8c\u6574\u6d41\u7a0b\u793a\u4f8b<\/h4>\n<h5>\u793a\u4f8b1&#xff1a;\u5b8c\u6574\u6587\u4ef6\u8bfb\u5199\u6d41\u7a0b<\/h5>\n<p>c<\/p>\n<p>#include &lt;stdio.h&gt;<br \/>\n#include &lt;stdlib.h&gt;<\/p>\n<p>int main() {<br \/>\n    FILE *fp &#061; NULL;<br \/>\n    char buffer[100];<\/p>\n<p>    \/\/ 1. \u6253\u5f00\u6587\u4ef6<br \/>\n    fp &#061; fopen(&#034;example.txt&#034;, &#034;w&#043;&#034;);<br \/>\n    if (fp &#061;&#061; NULL) {<br \/>\n        perror(&#034;Error opening file&#034;);<br \/>\n        return EXIT_FAILURE;<br \/>\n    }<\/p>\n<p>    \/\/ 2. \u5199\u5165\u6570\u636e&#xff08;\u591a\u79cd\u65b9\u5f0f&#xff09;<br \/>\n    fputs(&#034;Hello, World!\\\\n&#034;, fp);<br \/>\n    fprintf(fp, &#034;This is line %d\\\\n&#034;, 2);<br \/>\n    fputc(&#039;A&#039;, fp);<br \/>\n    fputc(&#039;\\\\n&#039;, fp);<\/p>\n<p>    \/\/ 3. \u91cd\u7f6e\u6587\u4ef6\u6307\u9488\u5230\u5f00\u5934<br \/>\n    rewind(fp);<\/p>\n<p>    \/\/ 4. \u8bfb\u53d6\u6570\u636e<br \/>\n    printf(&#034;File content:\\\\n&#034;);<br \/>\n    while (fgets(buffer, sizeof(buffer), fp) !&#061; NULL) {<br \/>\n        printf(&#034;%s&#034;, buffer);<br \/>\n    }<\/p>\n<p>    \/\/ 5. \u5173\u95ed\u6587\u4ef6<br \/>\n    fclose(fp);<\/p>\n<p>    return EXIT_SUCCESS;<br \/>\n}<\/p>\n<h3>&#x1f527; \u4e09\u3001IO\u7f16\u7a0b\u7ec3\u4e60\u9898\u8be6\u89e3<\/h3>\n<h4>3.1 \u7ec3\u4e601&#xff1a;\u6587\u4ef6\u62f7\u8d1d\u7a0b\u5e8f<\/h4>\n<p>\u8981\u6c42&#xff1a;\u4ece\u7ec8\u7aef\u63a5\u6536\u4e24\u4e2a\u6587\u4ef6\u8def\u5f84&#xff0c;\u5c06\u7b2c\u4e00\u4e2a\u6587\u4ef6\u5185\u5bb9\u62f7\u8d1d\u5230\u7b2c\u4e8c\u4e2a\u6587\u4ef6<\/p>\n<p>c<\/p>\n<p>#include &lt;stdio.h&gt;<br \/>\n#include &lt;stdlib.h&gt;<\/p>\n<p>int main(int argc, char *argv[]) {<br \/>\n    FILE *src, *dst;<br \/>\n    int ch;<\/p>\n<p>    \/\/ \u68c0\u67e5\u53c2\u6570\u6570\u91cf<br \/>\n    if (argc !&#061; 3) {<br \/>\n        fprintf(stderr, &#034;Usage: %s &lt;source&gt; &lt;destination&gt;\\\\n&#034;, argv[0]);<br \/>\n        return 1;<br \/>\n    }<\/p>\n<p>    \/\/ \u6253\u5f00\u6e90\u6587\u4ef6<br \/>\n    src &#061; fopen(argv[1], &#034;r&#034;);<br \/>\n    if (src &#061;&#061; NULL) {<br \/>\n        perror(&#034;Error opening source file&#034;);<br \/>\n        return 1;<br \/>\n    }<\/p>\n<p>    \/\/ \u6253\u5f00\u76ee\u6807\u6587\u4ef6<br \/>\n    dst &#061; fopen(argv[2], &#034;w&#034;);<br \/>\n    if (dst &#061;&#061; NULL) {<br \/>\n        perror(&#034;Error opening destination file&#034;);<br \/>\n        fclose(src);<br \/>\n        return 1;<br \/>\n    }<\/p>\n<p>    \/\/ \u62f7\u8d1d\u5185\u5bb9<br \/>\n    while ((ch &#061; fgetc(src)) !&#061; EOF) {<br \/>\n        fputc(ch, dst);<br \/>\n    }<\/p>\n<p>    \/\/ \u68c0\u67e5\u662f\u5426\u8bfb\u53d6\u9519\u8bef<br \/>\n    if (ferror(src)) {<br \/>\n        fprintf(stderr, &#034;Error reading from source file\\\\n&#034;);<br \/>\n    }<\/p>\n<p>    \/\/ \u5173\u95ed\u6587\u4ef6<br \/>\n    fclose(src);<br \/>\n    fclose(dst);<\/p>\n<p>    printf(&#034;File copied successfully from %s to %s\\\\n&#034;, argv[1], argv[2]);<br \/>\n    return 0;<br \/>\n}<\/p>\n<p>\u7f16\u8bd1\u4e0e\u8fd0\u884c&#xff1a;<\/p>\n<p>bash<\/p>\n<p>gcc file_copy.c -o file_copy<br \/>\n.\/file_copy source.txt destination.txt<\/p>\n<h4>3.2 \u7ec3\u4e602&#xff1a;\u5b57\u7b26\u9891\u7387\u7edf\u8ba1\u7a0b\u5e8f<\/h4>\n<p>\u8981\u6c42&#xff1a;\u7edf\u8ba1\u6587\u4ef6\u4e2d\u51fa\u73b0\u6b21\u6570\u6700\u591a\u7684\u5b57\u7b26\u53ca\u5176\u51fa\u73b0\u6b21\u6570<\/p>\n<p>c<\/p>\n<p>#include &lt;stdio.h&gt;<br \/>\n#include &lt;ctype.h&gt;<br \/>\n#include &lt;stdlib.h&gt;<\/p>\n<p>#define ASCII_SIZE 256<\/p>\n<p>int main(int argc, char *argv[]) {<br \/>\n    FILE *fp;<br \/>\n    int freq[ASCII_SIZE] &#061; {0};<br \/>\n    int ch;<br \/>\n    int max_index &#061; 0;<\/p>\n<p>    \/\/ \u68c0\u67e5\u53c2\u6570<br \/>\n    if (argc !&#061; 2) {<br \/>\n        fprintf(stderr, &#034;Usage: %s &lt;filename&gt;\\\\n&#034;, argv[0]);<br \/>\n        return 1;<br \/>\n    }<\/p>\n<p>    \/\/ \u6253\u5f00\u6587\u4ef6<br \/>\n    fp &#061; fopen(argv[1], &#034;r&#034;);<br \/>\n    if (fp &#061;&#061; NULL) {<br \/>\n        perror(&#034;Error opening file&#034;);<br \/>\n        return 1;<br \/>\n    }<\/p>\n<p>    \/\/ \u7edf\u8ba1\u5b57\u7b26\u9891\u7387<br \/>\n    while ((ch &#061; fgetc(fp)) !&#061; EOF) {<br \/>\n        \/\/ \u53ea\u7edf\u8ba1\u53ef\u6253\u5370\u5b57\u7b26<br \/>\n        if (isprint(ch)) {<br \/>\n            freq[ch]&#043;&#043;;<br \/>\n            if (freq[ch] &gt; freq[max_index]) {<br \/>\n                max_index &#061; ch;<br \/>\n            }<br \/>\n        }<br \/>\n    }<\/p>\n<p>    \/\/ \u663e\u793a\u7ed3\u679c<br \/>\n    if (freq[max_index] &gt; 0) {<br \/>\n        printf(&#034;Most frequent character: &#039;%c&#039; (ASCII: %d)\\\\n&#034;,<br \/>\n               max_index, max_index);<br \/>\n        printf(&#034;Frequency: %d times\\\\n&#034;, freq[max_index]);<\/p>\n<p>        \/\/ \u53ef\u9009&#xff1a;\u663e\u793a\u6240\u6709\u5b57\u7b26\u9891\u7387<br \/>\n        printf(&#034;\\\\nCharacter frequency table:\\\\n&#034;);<br \/>\n        printf(&#034;Char | Count\\\\n&#034;);<br \/>\n        printf(&#034;&#8212;&#8211;|&#8212;&#8212;\\\\n&#034;);<br \/>\n        for (int i &#061; 0; i &lt; ASCII_SIZE; i&#043;&#043;) {<br \/>\n            if (freq[i] &gt; 0 &amp;&amp; isprint(i)) {<br \/>\n                printf(&#034;  %c  |  %d\\\\n&#034;, i, freq[i]);<br \/>\n            }<br \/>\n        }<br \/>\n    } else {<br \/>\n        printf(&#034;File is empty or contains no printable characters.\\\\n&#034;);<br \/>\n    }<\/p>\n<p>    fclose(fp);<br \/>\n    return 0;<br \/>\n}<\/p>\n<p>\u7f16\u8bd1\u4e0e\u8fd0\u884c&#xff1a;<\/p>\n<p>bash<\/p>\n<p>gcc char_freq.c -o char_freq<br \/>\n.\/char_freq example.txt<\/p>\n<h4>3.3 \u6269\u5c55\u7ec3\u4e60&#xff1a;\u5e26\u7f13\u5b58\u7684\u6279\u91cf\u62f7\u8d1d&#xff08;\u4f18\u5316\u7248&#xff09;<\/h4>\n<p>c<\/p>\n<p>#include &lt;stdio.h&gt;<br \/>\n#include &lt;stdlib.h&gt;<br \/>\n#include &lt;time.h&gt;<\/p>\n<p>#define BUFFER_SIZE 4096  \/\/ 4KB\u7f13\u51b2\u533a&#xff0c;\u5339\u914d\u5168\u7f13\u5b58\u5927\u5c0f<\/p>\n<p>int main(int argc, char *argv[]) {<br \/>\n    FILE *src, *dst;<br \/>\n    char buffer[BUFFER_SIZE];<br \/>\n    size_t bytes_read, total_bytes &#061; 0;<br \/>\n    clock_t start, end;<br \/>\n    double cpu_time_used;<\/p>\n<p>    if (argc !&#061; 3) {<br \/>\n        fprintf(stderr, &#034;Usage: %s &lt;source&gt; &lt;destination&gt;\\\\n&#034;, argv[0]);<br \/>\n        return 1;<br \/>\n    }<\/p>\n<p>    start &#061; clock();<\/p>\n<p>    src &#061; fopen(argv[1], &#034;rb&#034;);  \/\/ \u4e8c\u8fdb\u5236\u6a21\u5f0f\u8bfb\u53d6<br \/>\n    if (!src) {<br \/>\n        perror(&#034;Source file error&#034;);<br \/>\n        return 1;<br \/>\n    }<\/p>\n<p>    dst &#061; fopen(argv[2], &#034;wb&#034;);  \/\/ \u4e8c\u8fdb\u5236\u6a21\u5f0f\u5199\u5165<br \/>\n    if (!dst) {<br \/>\n        perror(&#034;Destination file error&#034;);<br \/>\n        fclose(src);<br \/>\n        return 1;<br \/>\n    }<\/p>\n<p>    \/\/ \u4f7f\u7528\u7f13\u51b2\u533a\u6279\u91cf\u8bfb\u5199<br \/>\n    while ((bytes_read &#061; fread(buffer, 1, BUFFER_SIZE, src)) &gt; 0) {<br \/>\n        fwrite(buffer, 1, bytes_read, dst);<br \/>\n        total_bytes &#043;&#061; bytes_read;<br \/>\n    }<\/p>\n<p>    \/\/ \u68c0\u67e5\u9519\u8bef<br \/>\n    if (ferror(src)) {<br \/>\n        fprintf(stderr, &#034;Error reading source file\\\\n&#034;);<br \/>\n    }<br \/>\n    if (ferror(dst)) {<br \/>\n        fprintf(stderr, &#034;Error writing to destination file\\\\n&#034;);<br \/>\n    }<\/p>\n<p>    fclose(src);<br \/>\n    fclose(dst);<\/p>\n<p>    end &#061; clock();<br \/>\n    cpu_time_used &#061; ((double)(end &#8211; start)) \/ CLOCKS_PER_SEC;<\/p>\n<p>    printf(&#034;Copy completed successfully!\\\\n&#034;);<br \/>\n    printf(&#034;Total bytes copied: %ld\\\\n&#034;, total_bytes);<br \/>\n    printf(&#034;Time used: %.6f seconds\\\\n&#034;, cpu_time_used);<br \/>\n    printf(&#034;Transfer rate: %.2f KB\/s\\\\n&#034;,<br \/>\n           total_bytes \/ 1024.0 \/ cpu_time_used);<\/p>\n<p>    return 0;<br \/>\n}<\/p>\n<h3>&#x1f4ca; \u56db\u3001IO\u7f16\u7a0b\u5b9e\u8df5\u6280\u5de7\u4e0e\u6ce8\u610f\u4e8b\u9879<\/h3>\n<h4>4.1 \u9519\u8bef\u5904\u7406\u6700\u4f73\u5b9e\u8df5<\/h4>\n<p>c<\/p>\n<p>\/\/ \u4e0d\u597d\u7684\u5199\u6cd5<br \/>\nFILE *fp &#061; fopen(&#034;file.txt&#034;, &#034;r&#034;);<br \/>\n\/\/ \u76f4\u63a5\u4f7f\u7528fp&#xff0c;\u4e0d\u68c0\u67e5\u662f\u5426\u6210\u529f<\/p>\n<p>\/\/ \u597d\u7684\u5199\u6cd5<br \/>\nFILE *fp &#061; fopen(&#034;file.txt&#034;, &#034;r&#034;);<br \/>\nif (fp &#061;&#061; NULL) {<br \/>\n    \/\/ \u4f7f\u7528perror\u63d0\u4f9b\u8be6\u7ec6\u4fe1\u606f<br \/>\n    perror(&#034;Error opening file&#034;);<\/p>\n<p>    \/\/ \u6216\u8005\u4f7f\u7528strerror<br \/>\n    fprintf(stderr, &#034;Error: %s\\\\n&#034;, strerror(errno));<\/p>\n<p>    return EXIT_FAILURE;<br \/>\n}<\/p>\n<h4>4.2 \u8d44\u6e90\u7ba1\u7406&#xff08;\u9632\u6b62\u5185\u5b58\/\u6587\u4ef6\u6cc4\u6f0f&#xff09;<\/h4>\n<p>c<\/p>\n<p>\/\/ \u5b89\u5168\u5730\u6253\u5f00\u591a\u4e2a\u6587\u4ef6<br \/>\nFILE *fp1 &#061; NULL, *fp2 &#061; NULL, *fp3 &#061; NULL;<\/p>\n<p>fp1 &#061; fopen(&#034;file1.txt&#034;, &#034;r&#034;);<br \/>\nif (!fp1) goto cleanup;<\/p>\n<p>fp2 &#061; fopen(&#034;file2.txt&#034;, &#034;r&#034;);<br \/>\nif (!fp2) goto cleanup;<\/p>\n<p>fp3 &#061; fopen(&#034;file3.txt&#034;, &#034;w&#034;);<br \/>\nif (!fp3) goto cleanup;<\/p>\n<p>\/\/ \u6b63\u5e38\u5904\u7406\u903b\u8f91&#8230;<\/p>\n<p>cleanup:<br \/>\n\/\/ \u5b89\u5168\u5173\u95ed\u6240\u6709\u6253\u5f00\u7684\u6587\u4ef6<br \/>\nif (fp1) fclose(fp1);<br \/>\nif (fp2) fclose(fp2);<br \/>\nif (fp3) fclose(fp3);<\/p>\n<h4>4.3 \u7f13\u5b58\u5237\u65b0\u7b56\u7565<\/h4>\n<p>c<\/p>\n<p>\/\/ \u9700\u8981\u5b9e\u65f6\u5199\u5165\u65e5\u5fd7\u7684\u573a\u666f<br \/>\nFILE *log_file &#061; fopen(&#034;app.log&#034;, &#034;a&#034;);<br \/>\nif (log_file) {<br \/>\n    \/\/ \u8bbe\u7f6e\u884c\u7f13\u5b58<br \/>\n    setvbuf(log_file, NULL, _IOLBF, 0);<\/p>\n<p>    fprintf(log_file, &#034;Event 1 occurred\\\\n&#034;);<br \/>\n    fflush(log_file);  \/\/ \u7acb\u5373\u5199\u5165&#xff0c;\u4e0d\u7b49\u5f85\u7f13\u5b58\u6ee1<\/p>\n<p>    fprintf(log_file, &#034;Event 2 occurred\\\\n&#034;);<br \/>\n    fclose(log_file);<br \/>\n}<\/p>\n<h4><\/h4>\n<h3>&#x1f4dd; \u4e94\u3001\u603b\u7ed3\u4e0e\u5b66\u4e60\u5efa\u8bae<\/h3>\n<h4>5.1 \u6838\u5fc3\u8981\u70b9\u56de\u987e<\/h4>\n<li>\n<p>\u7edf\u4e00\u6587\u4ef6\u6a21\u578b&#xff1a;Linux\u5c06\u6240\u6709I\/O\u5bf9\u8c61\u62bd\u8c61\u4e3a\u6587\u4ef6<\/p>\n<\/li>\n<li>\n<p>\u4e09\u5c42I\/O\u4f53\u7cfb&#xff1a;\u6807\u51c6I\/O&#xff08;\u7f13\u5b58&#xff09;\u3001\u6587\u4ef6I\/O&#xff08;\u65e0\u7f13\u5b58&#xff09;\u3001\u76ee\u5f55I\/O<\/p>\n<\/li>\n<li>\n<p>\u7f13\u5b58\u673a\u5236&#xff1a;\u7406\u89e3\u5168\u7f13\u5b58\u3001\u884c\u7f13\u5b58\u3001\u65e0\u7f13\u5b58\u7684\u533a\u522b\u4e0e\u5e94\u7528\u573a\u666f<\/p>\n<\/li>\n<li>\n<p>\u9519\u8bef\u5904\u7406&#xff1a;\u59cb\u7ec8\u68c0\u67e5I\/O\u51fd\u6570\u8fd4\u56de\u503c&#xff0c;\u4f7f\u7528perror\/strerror<\/p>\n<\/li>\n<h4>5.2 \u5b66\u4e60\u8def\u5f84\u5efa\u8bae<\/h4>\n<p>text<\/p>\n<p>\u7b2c\u4e00\u9636\u6bb5&#xff1a;\u57fa\u7840\u638c\u63e1<br \/>\n\u251c\u2500\u2500 \u7406\u89e3&#034;\u4e00\u5207\u7686\u662f\u6587\u4ef6&#034;\u7406\u5ff5<br \/>\n\u251c\u2500\u2500 \u638c\u63e1\u6807\u51c6I\/O\u57fa\u672c\u51fd\u6570&#xff08;fopen\/fclose\/fputc\/fgetc&#xff09;<br \/>\n\u2514\u2500\u2500 \u5b8c\u6210\u7b80\u5355\u6587\u4ef6\u64cd\u4f5c\u7ec3\u4e60<\/p>\n<p>\u7b2c\u4e8c\u9636\u6bb5&#xff1a;\u719f\u7ec3\u5e94\u7528<br \/>\n\u251c\u2500\u2500 \u638c\u63e1\u683c\u5f0f\u5316I\/O&#xff08;fprintf\/fscanf&#xff09;<br \/>\n\u251c\u2500\u2500 \u7406\u89e3\u7f13\u5b58\u673a\u5236\u4e0e\u5237\u65b0\u7b56\u7565<br \/>\n\u251c\u2500\u2500 \u5b66\u4e60\u4e8c\u8fdb\u5236\u6587\u4ef6\u64cd\u4f5c<br \/>\n\u2514\u2500\u2500 \u5b8c\u6210\u590d\u6742\u6587\u4ef6\u5904\u7406\u4efb\u52a1<\/p>\n<p>\u7b2c\u4e09\u9636\u6bb5&#xff1a;\u9ad8\u7ea7\u4f18\u5316<br \/>\n\u251c\u2500\u2500 \u6027\u80fd\u5206\u6790\u4e0e\u8c03\u4f18<br \/>\n\u251c\u2500\u2500 \u9519\u8bef\u5904\u7406\u4e0e\u8d44\u6e90\u7ba1\u7406<br \/>\n\u251c\u2500\u2500 \u8de8\u5e73\u53f0\u517c\u5bb9\u6027\u5904\u7406<br \/>\n\u2514\u2500\u2500 \u5b9e\u9645\u9879\u76ee\u5e94\u7528<\/p>\n<h4>5.3 \u63a8\u8350\u7ec3\u4e60\u9879\u76ee<\/h4>\n<li>\n<p>\u5b9e\u73b0\u4e00\u4e2a\u7b80\u5355\u7684\u6587\u672c\u7f16\u8f91\u5668&#xff1a;\u652f\u6301\u6253\u5f00\u3001\u7f16\u8f91\u3001\u4fdd\u5b58\u6587\u4ef6<\/p>\n<\/li>\n<li>\n<p>\u65e5\u5fd7\u7cfb\u7edf&#xff1a;\u5b9e\u73b0\u5e26\u7f13\u51b2\u7684\u65e5\u5fd7\u8bb0\u5f55&#xff0c;\u652f\u6301\u65e5\u5fd7\u8f6e\u8f6c<\/p>\n<\/li>\n<li>\n<p>\u914d\u7f6e\u6587\u4ef6\u89e3\u6790\u5668&#xff1a;\u8bfb\u53d6\/\u5199\u5165INI\u3001JSON\u6216XML\u683c\u5f0f\u914d\u7f6e<\/p>\n<\/li>\n<li>\n<p>\u6570\u636e\u683c\u5f0f\u8f6c\u6362\u5de5\u5177&#xff1a;\u5728\u4e0d\u540c\u683c\u5f0f&#xff08;CSV\u3001\u4e8c\u8fdb\u5236\u3001\u6587\u672c&#xff09;\u95f4\u8f6c\u6362<\/p>\n<\/li>\n<h4>5.4 \u5e38\u89c1\u9677\u9631\u4e0e\u89e3\u51b3\u65b9\u6848<\/h4>\n<table>\n<tr>\u95ee\u9898\u539f\u56e0\u89e3\u51b3\u65b9\u6848<\/tr>\n<tbody>\n<tr>\n<td>\u6587\u4ef6\u672b\u5c3e\u591a\u51fa\u7a7a\u884c<\/td>\n<td>fgets\u4fdd\u7559\u6362\u884c\u7b26<\/td>\n<td>\u624b\u52a8\u53bb\u9664\\\\n<\/td>\n<\/tr>\n<tr>\n<td>\u5199\u5165\u5185\u5bb9\u4e0d\u7acb\u5373\u663e\u793a<\/td>\n<td>\u7f13\u5b58\u672a\u5237\u65b0<\/td>\n<td>\u4f7f\u7528fflush\u6216\u8bbe\u7f6e\u65e0\u7f13\u5b58<\/td>\n<\/tr>\n<tr>\n<td>\u5927\u6587\u4ef6\u590d\u5236\u6162<\/td>\n<td>\u5355\u5b57\u7b26\u590d\u5236\u6548\u7387\u4f4e<\/td>\n<td>\u4f7f\u7528\u7f13\u51b2\u533a\u6279\u91cf\u590d\u5236<\/td>\n<\/tr>\n<tr>\n<td>\u4e8c\u8fdb\u5236\u6587\u4ef6\u635f\u574f<\/td>\n<td>\u6587\u672c\u6a21\u5f0f\u5904\u7406\u4e8c\u8fdb\u5236<\/td>\n<td>\u4f7f\u7528&#034;rb&#034;\u3001&#034;wb&#034;\u6a21\u5f0f<\/td>\n<\/tr>\n<tr>\n<td>\u8de8\u5e73\u53f0\u6362\u884c\u7b26\u95ee\u9898<\/td>\n<td>Windows\/Linux\u5dee\u5f02<\/td>\n<td>\u7edf\u4e00\u5904\u7406\u6216\u4f7f\u7528\u4e8c\u8fdb\u5236\u6a21\u5f0f<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n","protected":false},"excerpt":{"rendered":"<p>&#x1f4d8; \u4e00\u3001Linux IO\u7f16\u7a0b\u6838\u5fc3\u6982\u5ff51.1 \\&#8221;\u4e00\u5207\u7686\u662f\u6587\u4ef6\\&#8221;\u7684\u7406\u5ff5\u5728Linux\u7cfb\u7edf\u4e2d&#xff0c;\u6240\u6709\u8f93\u5165\u8f93\u51fa\u64cd\u4f5c\u90fd\u7edf\u4e00\u4e3a\u6587\u4ef6\u64cd\u4f5c&#xff0c;\u5177\u4f53\u5206\u4e3a\u4ee5\u4e0b\u51e0\u7c7b&#xff1a;\u6587\u4ef6\u7c7b\u578b\u6807\u8bc6\u7b26\u8bf4\u660e\u5178\u578b\u8bbe\u5907\u5757\u8bbe\u5907\u6587\u4ef6b\u6309\u5757\u8bbf\u95ee\u7684\u5b58\u50a8\u8bbe\u5907\u786c\u76d8\u3001U\u76d8\u5b57\u7b26\u8bbe\u5907\u6587\u4ef6c\u6309\u5b57\u7b26\u8bbf\u95ee\u7684\u8bbe\u5907\u952e\u76d8\u3001\u9f20\u6807\u3001\u7ec8\u7aef\u76ee\u5f55\u6587\u4ef6d\u5b58\u50a8\u6587\u4ef6\u4fe1\u606f\u7684\u5bb9\u5668\u6587\u4ef6\u5939\u666e\u901a\u6587\u4ef6-\u5e38\u89c4\u6570\u636e\u6587\u4ef6\u6587\u672c\u3001\u4e8c\u8fdb\u5236\u6587\u4ef6\u94fe\u63a5\u6587\u4ef6l\u6307\u5411\u5176\u4ed6\u6587\u4ef6\u7684\u5feb\u6377\u65b9\u5f0f\u7b26\u53f7\u94fe\u63a5\u3001\u786c\u94fe\u63a5\u5957\u63a5\u5b57\u6587\u4ef6s\u8fdb\u7a0b\u95f4\u901a\u4fe1\u6587\u4ef6\u7f51\u7edcsocket\u7ba1\u9053\u6587\u4ef6p<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[58,43,44],"topic":[],"class_list":["post-72970","post","type-post","status-publish","format-standard","hentry","category-server","tag-linux","tag-43","tag-44"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Linux\u8f6f\u4ef6\u7f16\u7a0b\uff1aIO\u7f16\u7a0b\uff081\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/72970.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Linux\u8f6f\u4ef6\u7f16\u7a0b\uff1aIO\u7f16\u7a0b\uff081\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"&#x1f4d8; \u4e00\u3001Linux IO\u7f16\u7a0b\u6838\u5fc3\u6982\u5ff51.1 &quot;\u4e00\u5207\u7686\u662f\u6587\u4ef6&quot;\u7684\u7406\u5ff5\u5728Linux\u7cfb\u7edf\u4e2d&#xff0c;\u6240\u6709\u8f93\u5165\u8f93\u51fa\u64cd\u4f5c\u90fd\u7edf\u4e00\u4e3a\u6587\u4ef6\u64cd\u4f5c&#xff0c;\u5177\u4f53\u5206\u4e3a\u4ee5\u4e0b\u51e0\u7c7b&#xff1a;\u6587\u4ef6\u7c7b\u578b\u6807\u8bc6\u7b26\u8bf4\u660e\u5178\u578b\u8bbe\u5907\u5757\u8bbe\u5907\u6587\u4ef6b\u6309\u5757\u8bbf\u95ee\u7684\u5b58\u50a8\u8bbe\u5907\u786c\u76d8\u3001U\u76d8\u5b57\u7b26\u8bbe\u5907\u6587\u4ef6c\u6309\u5b57\u7b26\u8bbf\u95ee\u7684\u8bbe\u5907\u952e\u76d8\u3001\u9f20\u6807\u3001\u7ec8\u7aef\u76ee\u5f55\u6587\u4ef6d\u5b58\u50a8\u6587\u4ef6\u4fe1\u606f\u7684\u5bb9\u5668\u6587\u4ef6\u5939\u666e\u901a\u6587\u4ef6-\u5e38\u89c4\u6570\u636e\u6587\u4ef6\u6587\u672c\u3001\u4e8c\u8fdb\u5236\u6587\u4ef6\u94fe\u63a5\u6587\u4ef6l\u6307\u5411\u5176\u4ed6\u6587\u4ef6\u7684\u5feb\u6377\u65b9\u5f0f\u7b26\u53f7\u94fe\u63a5\u3001\u786c\u94fe\u63a5\u5957\u63a5\u5b57\u6587\u4ef6s\u8fdb\u7a0b\u95f4\u901a\u4fe1\u6587\u4ef6\u7f51\u7edcsocket\u7ba1\u9053\u6587\u4ef6p\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/72970.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-02-06T12:49:24+00:00\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/72970.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/72970.html\",\"name\":\"Linux\u8f6f\u4ef6\u7f16\u7a0b\uff1aIO\u7f16\u7a0b\uff081\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-02-06T12:49:24+00:00\",\"dateModified\":\"2026-02-06T12:49:24+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/72970.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/72970.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/72970.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Linux\u8f6f\u4ef6\u7f16\u7a0b\uff1aIO\u7f16\u7a0b\uff081\uff09\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Linux\u8f6f\u4ef6\u7f16\u7a0b\uff1aIO\u7f16\u7a0b\uff081\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/72970.html","og_locale":"zh_CN","og_type":"article","og_title":"Linux\u8f6f\u4ef6\u7f16\u7a0b\uff1aIO\u7f16\u7a0b\uff081\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"&#x1f4d8; \u4e00\u3001Linux IO\u7f16\u7a0b\u6838\u5fc3\u6982\u5ff51.1 \"\u4e00\u5207\u7686\u662f\u6587\u4ef6\"\u7684\u7406\u5ff5\u5728Linux\u7cfb\u7edf\u4e2d&#xff0c;\u6240\u6709\u8f93\u5165\u8f93\u51fa\u64cd\u4f5c\u90fd\u7edf\u4e00\u4e3a\u6587\u4ef6\u64cd\u4f5c&#xff0c;\u5177\u4f53\u5206\u4e3a\u4ee5\u4e0b\u51e0\u7c7b&#xff1a;\u6587\u4ef6\u7c7b\u578b\u6807\u8bc6\u7b26\u8bf4\u660e\u5178\u578b\u8bbe\u5907\u5757\u8bbe\u5907\u6587\u4ef6b\u6309\u5757\u8bbf\u95ee\u7684\u5b58\u50a8\u8bbe\u5907\u786c\u76d8\u3001U\u76d8\u5b57\u7b26\u8bbe\u5907\u6587\u4ef6c\u6309\u5b57\u7b26\u8bbf\u95ee\u7684\u8bbe\u5907\u952e\u76d8\u3001\u9f20\u6807\u3001\u7ec8\u7aef\u76ee\u5f55\u6587\u4ef6d\u5b58\u50a8\u6587\u4ef6\u4fe1\u606f\u7684\u5bb9\u5668\u6587\u4ef6\u5939\u666e\u901a\u6587\u4ef6-\u5e38\u89c4\u6570\u636e\u6587\u4ef6\u6587\u672c\u3001\u4e8c\u8fdb\u5236\u6587\u4ef6\u94fe\u63a5\u6587\u4ef6l\u6307\u5411\u5176\u4ed6\u6587\u4ef6\u7684\u5feb\u6377\u65b9\u5f0f\u7b26\u53f7\u94fe\u63a5\u3001\u786c\u94fe\u63a5\u5957\u63a5\u5b57\u6587\u4ef6s\u8fdb\u7a0b\u95f4\u901a\u4fe1\u6587\u4ef6\u7f51\u7edcsocket\u7ba1\u9053\u6587\u4ef6p","og_url":"https:\/\/www.wsisp.com\/helps\/72970.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-02-06T12:49:24+00:00","author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"6 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/72970.html","url":"https:\/\/www.wsisp.com\/helps\/72970.html","name":"Linux\u8f6f\u4ef6\u7f16\u7a0b\uff1aIO\u7f16\u7a0b\uff081\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-02-06T12:49:24+00:00","dateModified":"2026-02-06T12:49:24+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/72970.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/72970.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/72970.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"Linux\u8f6f\u4ef6\u7f16\u7a0b\uff1aIO\u7f16\u7a0b\uff081\uff09"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/72970","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=72970"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/72970\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=72970"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=72970"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=72970"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=72970"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}