{"id":43974,"date":"2025-06-16T14:28:14","date_gmt":"2025-06-16T06:28:14","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/43974.html"},"modified":"2025-06-16T14:28:14","modified_gmt":"2025-06-16T06:28:14","slug":"c%e8%af%ad%e8%a8%80-%e5%ad%a6%e4%b9%a0-%e6%96%87%e4%bb%b6%e6%93%8d%e4%bd%9c%e5%bc%80%e5%85%b3%e8%af%bb%e5%86%99%e5%ae%9a%e4%bd%8d%e5%a4%a7%e5%b0%8f%e6%93%8d%e4%bd%9c-2025%e5%b9%b46%e6%9c%888","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/43974.html","title":{"rendered":"C\u8bed\u8a00 \u5b66\u4e60 \u6587\u4ef6\u64cd\u4f5c(\u5f00\u5173,\u8bfb\u5199,\u5b9a\u4f4d,\u5927\u5c0f)\u64cd\u4f5c 2025\u5e746\u67088\u65e512:19:24"},"content":{"rendered":"<h2 style=\"text-align:center\">\u6587\u4ef6\u64cd\u4f5c<\/h2>\n<h3>\u6253\u5f00\u548c\u5173\u95ed\u64cd\u4f5c<\/h3>\n<h5>\u6253\u5f00\u6587\u4ef6&#xff08;fopen&#xff09;FILE *fopen(const char *filename, const char *mode);<\/h5>\n<p>mode(\u8d44\u6599\u6765\u6e90AI):<\/p>\n<table>\n<tbody>\n<tr>\u6a21\u5f0f\u63cf\u8ff0\u521b\u5efa\u6587\u4ef6\u6e05\u7a7a\u539f\u5185\u5bb9\u6587\u4ef6\u6307\u9488\u8d77\u59cb\u4f4d\u7f6e\u53ef\u8bfb&#xff1f;\u53ef\u5199&#xff1f;<\/tr>\n<tr>\n<td>&#034;r&#034;<\/td>\n<td>\u53ea\u8bfb\u6a21\u5f0f<\/td>\n<td>\u274c \u5426<\/td>\n<td>\u274c \u5426<\/td>\n<td>\u6587\u4ef6\u5f00\u5934<\/td>\n<td>\u2705 \u662f<\/td>\n<td>\u274c \u5426<\/td>\n<\/tr>\n<tr>\n<td>&#034;w&#034;<\/td>\n<td>\u5199\u5165\u6a21\u5f0f&#xff08;\u8986\u76d6&#xff09;<\/td>\n<td>\u2705 \u662f<\/td>\n<td>\u2705 \u662f&#xff08;\u6e05\u7a7a\u5df2\u6709\u5185\u5bb9&#xff09;<\/td>\n<td>\u6587\u4ef6\u5f00\u5934<\/td>\n<td>\u274c \u5426<\/td>\n<td>\u2705 \u662f<\/td>\n<\/tr>\n<tr>\n<td>&#034;a&#034;<\/td>\n<td>\u8ffd\u52a0\u5199\u5165\u6a21\u5f0f<\/td>\n<td>\u2705 \u662f<\/td>\n<td>\u274c \u5426&#xff08;\u4fdd\u7559\u539f\u5185\u5bb9&#xff09;<\/td>\n<td>\u6587\u4ef6\u672b\u5c3e<\/td>\n<td>\u274c \u5426<\/td>\n<td>\u2705 \u662f<\/td>\n<\/tr>\n<tr>\n<td>&#034;r&#043;&#034;<\/td>\n<td>\u8bfb\u5199\u6a21\u5f0f<\/td>\n<td>\u274c \u5426<\/td>\n<td>\u274c \u5426<\/td>\n<td>\u6587\u4ef6\u5f00\u5934<\/td>\n<td>\u2705 \u662f<\/td>\n<td>\u2705 \u662f<\/td>\n<\/tr>\n<tr>\n<td>&#034;w&#043;&#034;<\/td>\n<td>\u8bfb\u5199\u6a21\u5f0f&#xff08;\u8986\u76d6\/\u65b0\u5efa&#xff09;<\/td>\n<td>\u2705 \u662f<\/td>\n<td>\u2705 \u662f<\/td>\n<td>\u6587\u4ef6\u5f00\u5934<\/td>\n<td>\u2705 \u662f<\/td>\n<td>\u2705 \u662f<\/td>\n<\/tr>\n<tr>\n<td>&#034;a&#043;&#034;<\/td>\n<td>\u8bfb\u5199\u6a21\u5f0f&#xff08;\u8ffd\u52a0&#xff09;<\/td>\n<td>\u2705 \u662f<\/td>\n<td>\u274c \u5426<\/td>\n<td>\u6587\u4ef6\u672b\u5c3e<\/td>\n<td>\u2705 \u662f<\/td>\n<td><\/td>\n<\/tr>\n<tr>\n<td><\/td>\n<td><\/td>\n<td><\/td>\n<td><\/td>\n<td><\/td>\n<td><\/td>\n<td><\/td>\n<\/tr>\n<tr>\n<td>&#034;rb&#034;<\/td>\n<td>\u4ee5\u4e8c\u8fdb\u5236\u53ea\u8bfb\u65b9\u5f0f\u6253\u5f00<\/td>\n<td><\/td>\n<td><\/td>\n<td><\/td>\n<td><\/td>\n<td><\/td>\n<\/tr>\n<tr>\n<td>&#034;wb&#034;<\/td>\n<td>\u4ee5\u4e8c\u8fdb\u5236\u5199\u5165\u65b9\u5f0f\u6253\u5f00&#xff08;\u6e05\u7a7a&#xff09;<\/td>\n<td><\/td>\n<td><\/td>\n<td><\/td>\n<td><\/td>\n<td><\/td>\n<\/tr>\n<tr>\n<td>&#034;ab&#034;<\/td>\n<td>\u4ee5\u4e8c\u8fdb\u5236\u8ffd\u52a0\u65b9\u5f0f\u6253\u5f00<\/td>\n<td><\/td>\n<td><\/td>\n<td><\/td>\n<td><\/td>\n<td><\/td>\n<\/tr>\n<tr>\n<td>&#034;rb&#043;&#034;<\/td>\n<td>\u4ee5\u4e8c\u8fdb\u5236\u8bfb\u5199\u65b9\u5f0f\u6253\u5f00<\/td>\n<td><\/td>\n<td><\/td>\n<td><\/td>\n<td><\/td>\n<td><\/td>\n<\/tr>\n<tr>\n<td>&#034;wb&#043;&#034;<\/td>\n<td>\u4ee5\u4e8c\u8fdb\u5236\u8bfb\u5199\u65b9\u5f0f\u6253\u5f00&#xff08;\u6e05\u7a7a&#xff09;<\/td>\n<td><\/td>\n<td><\/td>\n<td><\/td>\n<td><\/td>\n<td><\/td>\n<\/tr>\n<tr>\n<td>&#034;ab&#043;&#034;<\/td>\n<td>\u4ee5\u4e8c\u8fdb\u5236\u8bfb\u5199\u65b9\u5f0f\u6253\u5f00&#xff08;\u8ffd\u52a0&#xff09;<\/td>\n<td><\/td>\n<td><\/td>\n<td><\/td>\n<td><\/td>\n<td><\/td>\n<\/tr>\n<tr>\n<td><\/td>\n<td><\/td>\n<td><\/td>\n<td><\/td>\n<td><\/td>\n<td><\/td>\n<td><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>#include &lt;stdio.h&gt;<\/p>\n<p>int main()<br \/>\n{<br \/>\n    FILE *fp;<\/p>\n<p>    \/\/ \u4ee5\u53ea\u8bfb\u65b9\u5f0f\u6253\u5f00\u6587\u4ef6<br \/>\n    fp &#061; fopen(&#034;022.txt&#034;, &#034;r&#034;);<\/p>\n<p>    if (fp &#061;&#061; NULL)<br \/>\n    {<br \/>\n        printf(&#034;Error: \u6587\u4ef6\u6253\u5f00\u5931\u8d25&#xff01;&#034;);<br \/>\n        return 0;<br \/>\n    }<br \/>\n    else<br \/>\n    {<br \/>\n        printf(&#034;File opened successfully\\\\n&#034;);<br \/>\n        fclose(fp);  \/\/ \u4f7f\u7528\u5b8c\u540e\u5173\u95ed\u6587\u4ef6<br \/>\n    }<\/p>\n<p>    return 0;<br \/>\n}<\/p>\n<h5>\u5173\u95ed\u6587\u4ef6&#xff08;fclose&#xff09;: <span style=\"color:#fe2c24\">\u64cd\u4f5c\u5b8c\u6210\u540e \u4e00\u5b9a\u8981\u5173\u95ed \u6587\u4ef6!<\/span><\/h5>\n<hr \/>\n<h3>\u8bfb\u5199\u6587\u4ef6\u64cd\u4f5c\u00a0\u00a0<\/h3>\n<p>\u8bfb\u5199\u6587\u4ef6&#xff08;fread \/ fwrite \/ fscanf \/ fprintf \/ fgets \/ fputs \u7b49&#xff09;<\/p>\n<h4 style=\"text-align:center\">\u5355\u5b57\u7b26 \u8bfb\u5199<\/h4>\n<p>\u00a0\u9010\u5b57\u7b26\u8bfb\u5199&#xff1a;fgetc\u00a0\/\u00a0fputc<\/p>\n<p>int fgetc(FILE *stream); \/\/ \u8bfb\u53d6\u4e00\u4e2a\u5b57\u7b26<\/p>\n<p>  int ch;<br \/>\n       while ((ch  &#061; fgetc(fp))!&#061;  EOF)<br \/>\n       {<br \/>\n        printf(&#034;%c&#034;, ch);<br \/>\n       } <\/p>\n<p>int fputc(int c, FILE *stream); \/\/ \u5199\u5165\u4e00\u4e2a\u5b57\u7b26\u00a0<\/p>\n<p>  FILE *fp;<\/p>\n<p>    \/\/ \u5199\u5165\u6587\u4ef6<br \/>\n    fp &#061; fopen(&#034;0235.txt&#034;, &#034;w&#034;);<br \/>\n    fputc(&#039;B&#039;, fp); \/\/\u5199\u5165\u4e00\u4e2a\u5b57\u7b26 <\/p>\n<\/p>\n<h4 style=\"text-align:center\">\u00a0 \u884c \u8bfb\u5199<\/h4>\n<h6>\u884c\u7ea7\u8bfb\u5199&#xff1a;fgets\u00a0\/\u00a0fputs<\/h6>\n<p>#include &lt;stdio.h&gt;<\/p>\n<p>int main()<br \/>\n{<br \/>\n    FILE *fp;<\/p>\n<p>    fp &#061; fopen(&#034;0235.txt&#034;, &#034;r&#034;);<br \/>\n    char line[1024];<br \/>\n  printf (&#034;%s&#034;, fgets(line, sizeof(line), fp)); \/\/\u8bfb\u53d6\u4e00\u884c<\/p>\n<p>    }<\/p>\n<h6>\u5199\u5165\u4e00\u884c<\/h6>\n<p>#include &lt;stdio.h&gt;<\/p>\n<p>int main()<br \/>\n{<br \/>\n    FILE *fp;<\/p>\n<p>    fp &#061; fopen(&#034;0235.txt&#034;, &#034;w&#034;);<br \/>\n    char line[1024]&#061;&#034;hello world&#034;;<br \/>\n    fputs(line, fp); \/\/\u5199\u5165\u4e00\u884c<br \/>\n    fclose(fp);<br \/>\n    fp &#061; fopen(&#034;0235.txt&#034;, &#034;r&#034;);<br \/>\n    char rline[1024];<br \/>\n    printf (&#034;%s&#034;,fgets(rline,1024,fp) );\/\/\u8bfb\u53d6\u4e00\u884c<br \/>\n    fclose(fp);<\/p>\n<p>    }<\/p>\n<h4 style=\"text-align:center\">\u683c\u5f0f\u5316\u8bfb\u5199<\/h4>\n<h5>\u683c\u5f0f\u5316\u8bfb\u5199&#xff1a;fscanf\u00a0\/\u00a0fprintf<\/h5>\n<p><span style=\"color:#fe2c24\">\u5199\u5165<\/span>\u548c\u8bfb\u53d6\u7ed3\u6784\u4f53\u6570\u636e&#xff08;\u6587\u672c\u683c\u5f0f&#xff09;<\/p>\n<p>#include &lt;stdio.h&gt;<br \/>\nvoid redefile(FILE *fp);\/\/\u8bfb\u53d6\u6587\u4ef6\u5e76\u8f93\u51fa\u51fd\u6570\u58f0\u660e<br \/>\ntypedef struct {<br \/>\nint id;<br \/>\nchar name[50];<\/p>\n<p>}Stdu;<br \/>\nStdu s1&#061; {1,&#034;wangwei&#034;};<br \/>\nint main()<br \/>\n{<br \/>\n    FILE *fp;<\/p>\n<p>    fp &#061; fopen(&#034;0235.txt&#034;, &#034;w&#043;&#034;);<br \/>\n    if(fp!&#061;NULL)<br \/>\n    {<br \/>\n        fprintf(fp,&#034;%d %s \\\\n&#034;,s1.id,s1.name);\/\/\u5199\u5165\u7ed3\u6784\u4f53 \u6587\u672c<br \/>\n        fclose(fp);<br \/>\n        redefile(fp);<br \/>\n    }<\/p>\n<p>    }<\/p>\n<p>void redefile(FILE *fp)<br \/>\n{<br \/>\n    fp&#061;fopen(&#034;0235.txt&#034;,&#034;r&#034;);<br \/>\n    if(fp!&#061;NULL)<br \/>\n    {<br \/>\n    char lile[1024];<br \/>\n      printf(&#034;%s&#034;,fgets(lile,1024,fp));<br \/>\n        fclose(fp);<br \/>\n    }<br \/>\n}<\/p>\n<p>\/\/&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;\u8f93\u51fa\u6548\u679c<\/p>\n<p>1 wangwei <\/p>\n<p><span style=\"color:#0d0016\">\u00a0\u5199\u5165<\/span>\u548c<span style=\"color:#fe2c24\">\u8bfb\u53d6<\/span>\u7ed3\u6784\u4f53\u6570\u636e&#xff08;\u6587\u672c\u683c\u5f0f&#xff09;<\/p>\n<p><span style=\"color:#fe2c24\">int fscanf(FILE *stream, const char *format, &#8230;);<\/span><\/p>\n<p>#include &lt;stdio.h&gt;<br \/>\nvoid redefile();<br \/>\ntypedef struct {<br \/>\nint id;<br \/>\nchar name[50];<\/p>\n<p>}Stdu;<br \/>\nStdu s1&#061; {1,&#034;wangwei&#034;};<br \/>\nint main()<br \/>\n{<br \/>\n    FILE *fp;<\/p>\n<p>    fp &#061; fopen(&#034;0235.txt&#034;, &#034;w&#043;&#034;);<br \/>\n    if(fp!&#061;NULL)<br \/>\n    {<br \/>\n        fprintf(fp,&#034;%d %s \\\\n&#034;,s1.id,s1.name); \/\/\u5199\u5165<br \/>\n        fclose(fp);<br \/>\n        redefile();<br \/>\n    }<\/p>\n<p>    }<\/p>\n<p>void redefile()<br \/>\n{<br \/>\n    FILE *fp;<br \/>\n    fp&#061;fopen(&#034;0235.txt&#034;,&#034;r&#034;);<br \/>\n    char lien[1024];<br \/>\n    if(fp!&#061;NULL)<br \/>\n    {<br \/>\n       if(fscanf(fp,&#034;%d %s&#034;,&amp;s1.id,s1.name)&#061;&#061;2)\/\/\u67e5\u627e<br \/>\n        {<br \/>\n            printf(&#034;&#8230;.\\\\n&#034;);<br \/>\n        }<br \/>\n        rewind(fp);\/\/\u8fd4\u56de\u6587\u4ef6\u5f00\u5934<br \/>\n        printf(&#034; %s \\\\n&#034;,fgets(lien,1024,fp));\/\/\u8bfb\u53d6\u8f93\u51fa<br \/>\n        fclose(fp);<br \/>\n    }<br \/>\n}<\/p>\n<ul>\n<li>\u6210\u529f\u5339\u914d\u5e76\u8d4b\u503c\u7684\u8f93\u5165\u9879\u6570\u91cf&#xff08;\u4f8b\u5982\u8bfb\u53d6\u4e86\u00a0%d %s&#xff0c;\u8fd4\u56de\u00a02&#xff09;<\/li>\n<li>\u5982\u679c\u5230\u8fbe\u6587\u4ef6\u672b\u5c3e\u6216\u53d1\u751f\u9519\u8bef&#xff0c;\u8fd4\u56de\u00a0EOF<\/li>\n<\/ul>\n<h4 style=\"text-align:center\">\u4e8c\u8fdb\u5236\u8bfb\u5199&#xff1a;fread\u00a0\/\u00a0fwrite\u00a0<\/h4>\n<p>#include &lt;stdio.h&gt;<\/p>\n<p>\/\/ \u51fd\u6570\u58f0\u660e&#xff1a;redefile \u7528\u4e8e\u4ece\u4e8c\u8fdb\u5236\u6587\u4ef6\u4e2d\u8bfb\u53d6\u7ed3\u6784\u4f53\u6570\u636e<br \/>\nvoid redefile();<\/p>\n<p>\/\/ \u5b9a\u4e49\u4e00\u4e2a\u7ed3\u6784\u4f53\u7c7b\u578b Stdu&#xff08;\u5b66\u751f&#xff09;<br \/>\ntypedef struct {<br \/>\n    int id;         \/\/ \u5b66\u751f ID<br \/>\n    char name[50];  \/\/ \u5b66\u751f\u59d3\u540d&#xff08;\u56fa\u5b9a\u957f\u5ea6\u5b57\u7b26\u6570\u7ec4&#xff09;<br \/>\n} Stdu;<\/p>\n<p>\/\/ \u5b9a\u4e49\u4e00\u4e2a\u5168\u5c40\u53d8\u91cf s1&#xff0c;\u5e76\u521d\u59cb\u5316<br \/>\nStdu s1 &#061; {1, &#034;wangwei&#034;};  \/\/ \u521d\u59cb ID \u4e3a 1&#xff0c;\u59d3\u540d\u4e3a &#034;wangwei&#034;<\/p>\n<p>int main()<br \/>\n{<br \/>\n    \/\/ \u58f0\u660e\u4e00\u4e2a\u6587\u4ef6\u6307\u9488 fp<br \/>\n    FILE *fp;<\/p>\n<p>    \/\/ \u4ee5 &#034;w&#043;&#034; \u6a21\u5f0f\u6253\u5f00\u6587\u4ef6&#xff08;\u53ef\u8bfb\u5199&#xff0c;\u6e05\u7a7a\u6216\u65b0\u5efa\u6587\u4ef6&#xff09;<br \/>\n    \/\/ \u6587\u4ef6\u540d\u4e3a &#034;0235.dat&#034;&#xff0c;\u901a\u5e38 .dat \u8868\u793a\u4e8c\u8fdb\u5236\u6570\u636e\u6587\u4ef6<br \/>\n    fp &#061; fopen(&#034;0235.dat&#034;, &#034;w&#043;&#034;);<\/p>\n<p>    if (fp !&#061; NULL)<br \/>\n    {<br \/>\n        \/\/ \u4f7f\u7528 fwrite \u5c06\u7ed3\u6784\u4f53 s1 \u5199\u5165\u6587\u4ef6<br \/>\n        \/\/ \u53c2\u6570\u8bf4\u660e&#xff1a;<br \/>\n        \/\/ &amp;s1             -&gt; \u8981\u5199\u5165\u7684\u7ed3\u6784\u4f53\u5730\u5740<br \/>\n        \/\/ sizeof(Stdu)   -&gt; \u6bcf\u4e2a\u7ed3\u6784\u4f53\u7684\u5927\u5c0f<br \/>\n        \/\/ 1              -&gt; \u5199\u5165 1 \u4e2a\u7ed3\u6784\u4f53<br \/>\n        \/\/ fp             -&gt; \u6587\u4ef6\u6307\u9488<br \/>\n        fwrite(&amp;s1, sizeof(Stdu), 1, fp);<\/p>\n<p>        \/\/ \u5173\u95ed\u6587\u4ef6\u6d41<br \/>\n        fclose(fp);<\/p>\n<p>        \/\/ \u8c03\u7528\u51fd\u6570 redefile()&#xff0c;\u7528\u4e8e\u4ece\u6587\u4ef6\u4e2d\u8bfb\u53d6\u5e76\u6253\u5370\u7ed3\u6784\u4f53\u5185\u5bb9<br \/>\n        redefile();<br \/>\n    }<\/p>\n<p>    return 0;<br \/>\n}<\/p>\n<p>\/**<br \/>\n * \u51fd\u6570\u540d\u79f0&#xff1a;redefile<br \/>\n * \u529f\u80fd&#xff1a;\u6253\u5f00\u4e8c\u8fdb\u5236\u6587\u4ef6\u5e76\u8bfb\u53d6\u5176\u4e2d\u7684\u7ed3\u6784\u4f53\u6570\u636e<br \/>\n *\/<br \/>\nvoid redefile()<br \/>\n{<br \/>\n    \/\/ \u58f0\u660e\u4e00\u4e2a\u65b0\u7684\u6587\u4ef6\u6307\u9488 fp<br \/>\n    FILE *fp;<\/p>\n<p>    \/\/ \u4ee5\u53ea\u8bfb\u4e8c\u8fdb\u5236\u6a21\u5f0f (&#034;rb&#034;) \u6253\u5f00\u4e4b\u524d\u5199\u5165\u7684\u6587\u4ef6<br \/>\n    fp &#061; fopen(&#034;0235.dat&#034;, &#034;rb&#034;);<\/p>\n<p>    \/\/ \u5224\u65ad\u6587\u4ef6\u662f\u5426\u6210\u529f\u6253\u5f00<br \/>\n    if (fp !&#061; NULL)<br \/>\n    {<br \/>\n        \/\/ \u58f0\u660e\u4e00\u4e2a\u7ed3\u6784\u4f53\u53d8\u91cf s&#xff0c;\u7528\u4e8e\u63a5\u6536\u8bfb\u53d6\u7684\u6570\u636e<br \/>\n        Stdu s;<\/p>\n<p>        \/\/ \u4f7f\u7528 fread \u5faa\u73af\u8bfb\u53d6\u7ed3\u6784\u4f53\u6570\u636e<br \/>\n        \/\/ fread \u8fd4\u56de\u503c\u662f\u6210\u529f\u8bfb\u53d6\u7684\u7ed3\u6784\u4f53\u6570\u91cf&#xff0c;\u7b49\u4e8e 1 \u8868\u793a\u8bfb\u53d6\u6210\u529f<br \/>\n        while (fread(&amp;s, sizeof(Stdu), 1, fp) &#061;&#061; 1)<br \/>\n        {<br \/>\n            \/\/ \u6253\u5370\u8bfb\u53d6\u5230\u7684\u5b66\u751f\u4fe1\u606f<br \/>\n            printf(&#034;ID: %d, Name: %s\\\\n&#034;, s.id, s.name);<br \/>\n        }<\/p>\n<p>        \/\/ \u5173\u95ed\u6587\u4ef6\u6d41<br \/>\n        fclose(fp);<br \/>\n    }<br \/>\n    else<br \/>\n    {<br \/>\n        \/\/ \u5982\u679c\u6587\u4ef6\u6253\u5f00\u5931\u8d25&#xff0c;\u8f93\u51fa\u63d0\u793a\u4fe1\u606f<br \/>\n        printf(&#034;\u65e0\u6cd5\u6253\u5f00\u6587\u4ef6\u8fdb\u884c\u8bfb\u53d6\\\\n&#034;);<br \/>\n    }<br \/>\n} <\/p>\n<h3>\u5b9a\u4f4d\u6587\u4ef6\u64cd\u4f5c<\/h3>\n<p>\u5b9a\u4f4d\u6587\u4ef6\u4f4d\u7f6e&#xff08;fseek \/ ftell \/ rewind&#xff09;<\/p>\n<\/p>\n<table>\n<tbody>\n<tr>\n<td>fseek(fp, offset, whence)<\/td>\n<td>\u8bbe\u7f6e\u6587\u4ef6\u6307\u9488\u4f4d\u7f6e<\/td>\n<td>fseek(fp, 10, SEEK_SET)<\/td>\n<\/tr>\n<tr>\n<td>ftell(fp)<\/td>\n<td>\u83b7\u53d6\u5f53\u524d\u6587\u4ef6\u6307\u9488\u4f4d\u7f6e<\/td>\n<td>long pos &#061; ftell(fp);<\/td>\n<\/tr>\n<tr>\n<td>rewind(fp)<\/td>\n<td>\u56de\u5230\u6587\u4ef6\u5f00\u5934<\/td>\n<td>rewind(fp);<\/td>\n<\/tr>\n<tr>\n<td>fflush(fp)<\/td>\n<td>\u5237\u65b0\u7f13\u51b2\u533a&#xff08;\u9002\u7528\u4e8e\u8f93\u51fa\u6d41&#xff09;<\/td>\n<td>fflush(fp);<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h4>\u00a0fseek\u51fd\u6570\u53c2\u6570\u8be6\u89e3:<\/h4>\n<table>\n<tbody>\n<tr>\n<td>fp<\/td>\n<td>FILE *<\/td>\n<td>\u6587\u4ef6\u6307\u9488&#xff0c;\u5fc5\u987b\u5148\u7528\u00a0fopen()\u00a0\u6253\u5f00\u6587\u4ef6<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<table>\n<tbody>\n<tr>\n<td>offset<\/td>\n<td>long<\/td>\n<td>\u504f\u79fb\u91cf&#xff08;\u5b57\u8282\u6570&#xff09;&#xff0c;\u53ef\u4e3a\u6b63\u4e5f\u53ef\u4e3a\u8d1f<\/td>\n<\/tr>\n<tr>\n<td>whence<\/td>\n<td>int<\/td>\n<td>\u5b9a\u4f4d\u8d77\u59cb\u70b9&#xff0c;\u53d6\u503c\u4e3a\u00a0SEEK_SET,\u00a0SEEK_CUR,\u00a0SEEK_END<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<table>\n<tr>whence \u503c\u542b\u4e49<\/tr>\n<tbody>\n<tr>\n<td>SEEK_SET<\/td>\n<td>\u6587\u4ef6\u5f00\u5934<\/td>\n<\/tr>\n<tr>\n<td>SEEK_CUR<\/td>\n<td>\u5f53\u524d\u4f4d\u7f6e<\/td>\n<\/tr>\n<tr>\n<td>SEEK_END<\/td>\n<td>\u6587\u4ef6\u672b\u5c3e<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u00a0<\/p>\n<h3>\u83b7\u53d6\u6587\u4ef6\u5927\u5c0f\u64cd\u4f5c<\/h3>\n<p>#include &lt;stdio.h&gt;<br \/>\nvoid redefile();<br \/>\ntypedef struct {<br \/>\nint id;<br \/>\nchar name[50];<\/p>\n<p>}Stdu;<br \/>\nStdu s1&#061; {1,&#034;wangwei&#034;};<br \/>\nint main()<br \/>\n{<br \/>\n    FILE *fp;<\/p>\n<p>    fp &#061; fopen(&#034;0235.txt&#034;, &#034;w&#034;);<br \/>\n    if(fp!&#061;NULL)<br \/>\n    {<br \/>\n        fputs(&#034;This is test&#034;,fp);\/\/\u5199\u5165\u4e00\u884c\u5230\u6587\u4ef6\u4e2d<br \/>\n        fclose(fp);<br \/>\n        redefile();<br \/>\n    }<\/p>\n<p>    }<\/p>\n<p>void redefile()<br \/>\n{<br \/>\n    FILE *fp;<br \/>\n    fp&#061;fopen(&#034;0235.txt&#034;,&#034;r&#034;);<br \/>\n   fseek(fp,0,SEEK_END);\/\/\u79fb\u52a8\u6587\u4ef6\u6307\u9488 \u8bbe\u7f6e\u6307\u9488\u4f4d\u7f6e0 \u4e3a\u6587\u4ef6\u672b\u5c3e<br \/>\n   long dft&#061;ftell(fp);\/\/\u83b7\u53d6\u6587\u4ef6\u6307\u9488\u4f4d\u7f6e<br \/>\n   printf(&#034;Size:%ld\\\\n&#034;,dft);\/\/\u8f93\u51fa\u6587\u4ef6\u6307\u9488\u4f4d\u7f6e<br \/>\n   char buf[1024];<br \/>\n   rewind(fp);\/\/\u56de\u5230\u6587\u4ef6\u5f00\u5934\u4f4d\u7f6e<br \/>\n   printf(&#034;%s&#034;,fgets(buf,1024,fp));\/\/\u8bfb\u53d6\u4e00\u884c\u5e76\u8f93\u51fa<br \/>\n   fclose(fp);<br \/>\n}<\/p>\n<h4>\u8fd0\u884c\u540e\u8f93\u51fa\u6548\u679c\u4e3a:<img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"54\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/06\/20250616062813-684fb97d74b79.png\" width=\"194\" \/>\u00a0<img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"655\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/06\/20250616062813-684fb97d7e5b5.png\" width=\"520\" \/><\/h4>\n<h2><span style=\"color:#fe2c24\">\u91cd\u70b9\u5c0f\u77e5\u8bc6:<\/span><\/h2>\n<\/p>\n<ul>\n<li>fopen()\u00a0\u9ed8\u8ba4\u5728 Windows \u4e0a\u4f7f\u7528\u7684\u662f ANSI \u7f16\u7801&#xff08;\u5373 GBK&#xff09;<\/li>\n<li>\u6240\u4ee5\u5f53\u4f60\u7684\u7a0b\u5e8f\u4ece UTF-8 \u7f16\u7801\u7684\u6e90\u6587\u4ef6\u4e2d\u7f16\u8bd1\u65f6&#xff0c;fopen()\u00a0\u4f1a\u628a\u00a0&#034;5\u6539.mix&#034;\u00a0\u5f53\u4f5c UTF-8 \u7f16\u7801\u7684\u5b57\u7b26\u4e32&#xff0c;\u4f46\u5b9e\u9645 Windows API \u8981\u6c42\u7684\u662f GBK \u6216 UTF-16<\/li>\n<li>\u7ed3\u679c\u5c31\u662f&#xff1a;\u6587\u4ef6\u540d\u89e3\u6790\u5931\u8d25&#xff0c;\u8fd4\u56de\u00a0NULL<\/li>\n<\/ul>\n<h4>\u89e3\u51b3\u529e\u6cd5:<\/h4>\n<table>\n<tbody>\n<tr>\n<td>_wfopen(L&#034;\u4e2d\u6587,\u6587\u4ef6\u540d&#034;, L &#034;r&#034;)<\/td>\n<td>\u4f7f\u7528\u5bbd\u5b57\u7b26\u5b57\u7b26\u4e32&#xff0c;\u517c\u5bb9 Windows Unicode API<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>  FILE *fp;<br \/>\n    fp&#061;_wfopen(L&#034;\u4e2d\u6587,\u6587\u4ef6\u540d&#034;,L&#034;r&#034;); <\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb987\u6b21\uff0c\u70b9\u8d5e21\u6b21\uff0c\u6536\u85cf8\u6b21\u3002\u64cd\u4f5c\u5b8c\u6210\u540e \u4e00\u5b9a\u8981\u5173\u95ed \u6587\u4ef6!\u548c\u8bfb\u53d6\u7ed3\u6784\u4f53\u6570\u636e\uff08\u6587\u672c\u683c\u5f0f\uff09\u7ed3\u6784\u4f53\u6570\u636e\uff08\u6587\u672c\u683c\u5f0f\uff09<\/p>\n","protected":false},"author":2,"featured_media":43972,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[174,4063,371,190],"topic":[],"class_list":["post-43974","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-server","tag-c","tag-c-","tag-371","tag-190"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>C\u8bed\u8a00 \u5b66\u4e60 \u6587\u4ef6\u64cd\u4f5c(\u5f00\u5173,\u8bfb\u5199,\u5b9a\u4f4d,\u5927\u5c0f)\u64cd\u4f5c 2025\u5e746\u67088\u65e512:19:24 - \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\/43974.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"C\u8bed\u8a00 \u5b66\u4e60 \u6587\u4ef6\u64cd\u4f5c(\u5f00\u5173,\u8bfb\u5199,\u5b9a\u4f4d,\u5927\u5c0f)\u64cd\u4f5c 2025\u5e746\u67088\u65e512:19:24 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb987\u6b21\uff0c\u70b9\u8d5e21\u6b21\uff0c\u6536\u85cf8\u6b21\u3002\u64cd\u4f5c\u5b8c\u6210\u540e \u4e00\u5b9a\u8981\u5173\u95ed \u6587\u4ef6!\u548c\u8bfb\u53d6\u7ed3\u6784\u4f53\u6570\u636e\uff08\u6587\u672c\u683c\u5f0f\uff09\u7ed3\u6784\u4f53\u6570\u636e\uff08\u6587\u672c\u683c\u5f0f\uff09\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/43974.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2025-06-16T06:28:14+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/06\/20250616062813-684fb97d74b79.png\" \/>\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=\"3 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/43974.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/43974.html\",\"name\":\"C\u8bed\u8a00 \u5b66\u4e60 \u6587\u4ef6\u64cd\u4f5c(\u5f00\u5173,\u8bfb\u5199,\u5b9a\u4f4d,\u5927\u5c0f)\u64cd\u4f5c 2025\u5e746\u67088\u65e512:19:24 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2025-06-16T06:28:14+00:00\",\"dateModified\":\"2025-06-16T06:28:14+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/43974.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/43974.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/43974.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"C\u8bed\u8a00 \u5b66\u4e60 \u6587\u4ef6\u64cd\u4f5c(\u5f00\u5173,\u8bfb\u5199,\u5b9a\u4f4d,\u5927\u5c0f)\u64cd\u4f5c 2025\u5e746\u67088\u65e512:19:24\"}]},{\"@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":"C\u8bed\u8a00 \u5b66\u4e60 \u6587\u4ef6\u64cd\u4f5c(\u5f00\u5173,\u8bfb\u5199,\u5b9a\u4f4d,\u5927\u5c0f)\u64cd\u4f5c 2025\u5e746\u67088\u65e512:19:24 - \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\/43974.html","og_locale":"zh_CN","og_type":"article","og_title":"C\u8bed\u8a00 \u5b66\u4e60 \u6587\u4ef6\u64cd\u4f5c(\u5f00\u5173,\u8bfb\u5199,\u5b9a\u4f4d,\u5927\u5c0f)\u64cd\u4f5c 2025\u5e746\u67088\u65e512:19:24 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb987\u6b21\uff0c\u70b9\u8d5e21\u6b21\uff0c\u6536\u85cf8\u6b21\u3002\u64cd\u4f5c\u5b8c\u6210\u540e \u4e00\u5b9a\u8981\u5173\u95ed \u6587\u4ef6!\u548c\u8bfb\u53d6\u7ed3\u6784\u4f53\u6570\u636e\uff08\u6587\u672c\u683c\u5f0f\uff09\u7ed3\u6784\u4f53\u6570\u636e\uff08\u6587\u672c\u683c\u5f0f\uff09","og_url":"https:\/\/www.wsisp.com\/helps\/43974.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2025-06-16T06:28:14+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/06\/20250616062813-684fb97d74b79.png"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"3 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/43974.html","url":"https:\/\/www.wsisp.com\/helps\/43974.html","name":"C\u8bed\u8a00 \u5b66\u4e60 \u6587\u4ef6\u64cd\u4f5c(\u5f00\u5173,\u8bfb\u5199,\u5b9a\u4f4d,\u5927\u5c0f)\u64cd\u4f5c 2025\u5e746\u67088\u65e512:19:24 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2025-06-16T06:28:14+00:00","dateModified":"2025-06-16T06:28:14+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/43974.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/43974.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/43974.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"C\u8bed\u8a00 \u5b66\u4e60 \u6587\u4ef6\u64cd\u4f5c(\u5f00\u5173,\u8bfb\u5199,\u5b9a\u4f4d,\u5927\u5c0f)\u64cd\u4f5c 2025\u5e746\u67088\u65e512:19:24"}]},{"@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\/43974","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=43974"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/43974\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media\/43972"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=43974"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=43974"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=43974"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=43974"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}