【C Primer Plus】第十三章 文件的输入/输出
2011-01-09 16:59
357 查看
<span id="_xhe_cursor"></span><span id="_xhe_temp" width="0" height="0" />\/* 13.11-1 修改程序清单13.1中的程序, 使之不采用命令行参数,而是请求用户输入文件名并读入用户的响应 13.1 count.c -- 使用标准I/O */ #include <stdio.h> #include <stdlib.h> // ANSI C的 exit() 原型 #define LEN 100 int main(void) { int ch; // 读取时存储每个字符的位置 char fname[LEN]; // 存储这件名 FILE *fp; // 文件指针 long count=0; printf("Enter your File fname:\n"); gets(fname); if((fp = fopen(fname, "r")) == NULL) { printf("Can't open %s for read", fname); exit(1); } while((ch = getc(fp)) != EOF) { putc(ch, stdout); // 相当于putchar(ch); count++; } fclose(fp); printf("\nFile %s has %ld characters.\n", fname, count); return 0; }
相关文章推荐
- C Primer Plus (第五版) 第十三章 文件输入/输出 编程练习
- C Primer Plus 第十三章——文件输入/输出
- C++ Primer Plus 之 输入、输出和文件
- C Primer Plus 第13章 文件输入/输出 13.11 编程练习答案
- C Primer Plus 第13章 文件输入/输出 13.1和文件进行通信
- c++ primer plus 第十七章 输入 输出 文件 IO iostream fstream
- c++primer plus第十七章-文件输入和输出
- c primer plus第13章总结:文件输入/输出
- 《C++ Primer Plus(第六版)》(42)(第十七章 输入、输出和文件 编程练习和答案2)
- C primer plus第13章(文件输入/输出)习题
- C primer plus第13章(文件输入/输出)对文本文件及二进制文件的处理
- C++ Primer Plus 第17章 输入,输出和文件
- 《C++ Primer Plus》第17章 输入、输出和文件 学习笔记
- C Primier Plus 第十三章 文件输入/输出
- C Primer Plus 第13章 文件输入/输出 13..5 随机存取fseek()和ftell()
- C++ Primer Plus(十七)——输入、输出和文件
- 《C++ Primer Plus(第六版)》(41)(第十七章 输入、输出和文件 编程练习和答案1)
- C Primer Plus之文件输入/输出
- C Primer Plus 第13章 文件输入/输出 13.7 其他标准I/O函数
- c++primer plus第十七章-cin输入、cout输出和文件I/O