1、
#include <stdio.h> #include <stdlib.h> int main(void) { int ch; FILE * fp; char filename[128]; int sum = 0; printf("please input filename: "); scanf("%s", filename); fp = fopen(filename, "r"); if(fp == NULL) { printf("file failed opened!\n"); exit(1); } while((ch = getc(fp)) != EOF) { putchar(ch); sum++; } printf("\nsum: %d.\n", sum); return 0; }
#include <stdio.h> int main(void) { char ch; int sum = 0; while((ch = getchar()) != EOF) { putchar(ch); sum++; } printf("sum: %d.\n", sum); return 0; }
#include <stdio.h> int main(void) { char ch; int sum = 0; while((ch = getchar()) != EOF) { putchar(ch); if(ch > ‘\040‘) sum++; } printf("sum: %d.\n", sum); return 0; }
#include <stdio.h> int main(void) { char ch; int sum = 0; while((ch = getchar()) != EOF) { putchar(ch); if(ch == ‘\n‘) sum++; } printf("sum: %d.\n", sum); return 0; }