c语言统计输入字符数及行数
1、
#include <stdio.h> #define STOP '|' int main(void) { char ch; int chnum = 0; int lines = 0; while((ch = getchar()) != STOP) { if(ch != '\n') chnum++; else lines++; } printf("ch number: %d.\n", chnum); printf("lines : %d.\n", lines + 1); return 0; }