【C语言程序设计第四版】练习12-4

字母转换并统计行数

#include <stdio.h>
#include <stdlib.h>


int main(void){
    
    
    char ch;
    int enter_count;
    FILE *fp;
    enter_count = 0;
    
    if ((fp=fopen("f12-2.txt", "r")) == NULL) {
        printf("File open errpr!
");
        exit(0);
    }
    
    while ((ch=fgetc(fp))!=EOF) {
        if (ch >= 'A' && ch <= 'Z') {
            ch = 'a' + (ch - 'A');
        }
        if (ch == '
') {
            enter_count++;
        }
        putchar(ch);
    }
    
    if ((fclose(fp))) {
        printf("Can not close the file!
");
        exit(0);
    }
    puts("");
    
    printf("File enter count number is %d.
", enter_count);
    
    return 0;
}
原文地址:https://www.cnblogs.com/sidianok/p/15343451.html