<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                [TOC] # 獲取光標位置ftell ~~~ #include<stdio.h> long ftell(FILE * stream); 功能: 獲取文件流(文件光標)的讀寫位置 參數: stream: 已經打開的文件指針 返回值: 成功: 當前文件流(文件光標)的讀寫位置 失敗: -1 ~~~ # 獲取文件狀態stat ~~~ #include<sys/types.h> #include<sys/stat.h> int stat(const char * path, struct stat * buf); 功能: 獲取文件狀態信息 參數: path: 文件名 buf: 保存文件信息的結構體 返回值: 成功: 0 失敗: -1 ~~~ ![](https://box.kancloud.cn/ee7c342f7402f4d5ace5d28b55b94805_1082x600.png) ~~~ #include <iostream> #include <stdio.h> #include <string.h> #include <stdlib.h> #include <sys/types.h> #include <sys/stat.h> int main() { struct stat s; stat("/Users/jdxia/Desktop/study/studyc++/b.txt", &s); printf("文件字節大小: %d\n", s.st_size); getchar(); return 0; } ~~~ # 刪除,重命名文件 **刪除文件remove** ~~~ #include<stdio.h> int remove(const char * pathname); 功能:刪除文件 參數: pathname: 文件名 返回值: 成功: 0 失敗: -1 ~~~ **重命名rename** ~~~ #include<stdio.h> int rename(const char * oldpath, const char * newpath); 功能: 把oldpath的文件名改為newpath 參數: oldpath: 舊文件名 newpath: 新文件名 返回值: 成功: 0 失敗: -1 ~~~ # 文件緩沖區 更新緩沖區 ~~~ #include<stdio.h> int fflush(FILE *stream); 功能: 更新緩沖區,讓緩沖區的數據立馬寫到文件中 參數: stream: 文件指針 返回值: 成功: 0 失敗: -1 ~~~ # 案例 ## vi 實現 ~~~ #include <stdio.h> #include<string.h> #include<stdlib.h> int main() { //指定一個文件名 char fileName[256]; printf("請輸入文件名: \n"); scanf("%s", fileName); //注意問題,用來接收換行 getchar(); //2. 打開文件 FILE *fp = fopen(fileName, "w"); //3. 判斷文件的可用性 if (!fp) { return -1; } //4. 循環寫入內容 char buf[1024]; while (1) { memset(buf, 0, 1024); fgets(buf, 1024, stdin); //5. 退出命令 comm=exit quit if (!strncmp("comm=exit", buf, 9)) { break; } //6.將字符串寫入文件中 int i = 0; while (buf[i]) { fputc(buf[i++], fp); } //更新緩沖區 fflush(fp); } //7、關閉文件 fclose(fp); getchar(); return 0; } ~~~ ## cat實現 ~~~ #include <stdio.h> #include<string.h> #include<stdlib.h> int main() { //指定一個文件名 char fileName[256]; printf("請輸入文件名: \n"); scanf("%s", fileName); //注意問題,用來接收換行 getchar(); //打開文件 FILE *fp = fopen(fileName, "r"); if (!fp) { return -1; } //文件的結束標志 EOF -1 char ch; while ((ch = fgetc(fp)) != EOF) { printf("%c", ch); } //關閉文件 fclose(fp); getchar(); return 0; } ~~~
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看