第 13 章 文件输入/输出 (标准I/O)

时间:2022-05-22 14:39:20
 /*--------------------------
count.c -- 使用标准 I/O
--------------------------*/ #include <stdio.h>
#include <stdlib.h> //提供 exit() 函数原型 int main(int argc, char *argv[])
{
int ch; //读取文件时,储存每个字符的地方
FILE *fp; //文件指针
unsigned long count = ; if (argc != )
{
printf("Usage: %s filename\n", argv[]);
exit(EXIT_FAILURE);
} if (NULL == (fp = fopen(argv[], "r")))
{
printf("Can't open %s\n", argv[]);
exit(EXIT_FAILURE);
} while (EOF != (ch = getc(fp)))
{
putc(ch, stdout); //同 putchar(ch)
++count;
} fclose(fp);
printf("File %s has %lu characters\n", argv[], count); return ;
}

count.c

第 13 章 文件输入/输出 (标准I/O)