1. #include <stdio.h> /* 标准输入/出头文件 */
    2. #include <stdlib.h> /* 包含库函数 system()所需要的信息 */
    3. int main(void) /* 主函数 main() */
    4. {
    5. FILE *fp; /* 文件指针 */
    6. int nLower = 0, nUpper = 0, nDigit = 0; /* 定义统计变量 */
    7. char ch; /* 定义字符变量 */
    8. char fileName[80]; /* 定义字符数组,用于打开的文件 */
    9. printf("输入文件名:"); /* 提示信息 */
    10. scanf("%s", fileName); /* 输入文件名 */
    11. if ((fp = fopen(fileName, "r")) == NULL) // 文件打开失败操作
    12. { /* 打开文件 */
    13. printf("打开文件%s 失败!\n", fileName);/* 错误信息 */
    14. system("PAUSE"); /* 调用库函数 system( ),输出系统提示信息 */
    15. exit(1); /* 退出程序 */
    16. }
    17. ch = fgetc(fp); /* 如何由文件中读入一个字符 */
    18. while (!feof(fp)) // 如何判断文件读取结束
    19. { /* 文件未结束 */
    20. if (ch >= 'a' && ch <= 'z') nLower++; /* 统计英文小写字母 */
    21. else if (ch >= 'A' && ch <= 'Z') nUpper++; /* 统计英文大写字母 */
    22. else if (ch >= '0' && ch <= '9') nDigit++; /* 统计英文数字字符 */
    23. ch = fgetc(fp); /* 由文件中读入一个字符 */
    24. }
    25. fclose(fp); /* 关闭文件 */
    26. printf("文件中包含:\n%d 个英文小写字母\n", nLower);/* 输出英文小写字母个数 */
    27. printf("%d 个英文大写字母\n", nUpper); /* 输出英文小写字母个数 */
    28. printf("%d 个数字字符\n", nDigit); /* 输出英文小写字母个数 */
    29. system("PAUSE"); /* 调用库函数 system( ),输出系统提示信息 */
    30. return 0; /* 返回值 0, 返回操作系统 */
    31. }