实验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); }