实验7

task4:
#include<stdio.h>

int main() {
    FILE *fp;
    fp = fopen("data4.txt", "r");
    if (fp == NULL) {
        return -1;
    }
    char t;
    int line_count = 0, char_count = 0;
    while (feof(fp) == 0) {
        t = fgetc(fp);
        if (t == EOF) {
            line_count++;
            break;
        }
        
        else if (t != ' ' && t != '\t') 
            char_count++;
        
        else if (t == '\n') 
            line_count++;
        
    }
    printf("data4.txt统计结果\n行数:%d\n字数:%d", line_count ,char_count);
}

 

posted @ 2024-12-26 16:17  jjjrrhhhhh  阅读(0)  评论(0编辑  收藏  举报