/*--------------------------
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