1-17 编写一个程序,打印长度大于80个字符的所有输入行
#include<stdio.h> #define MINLENGTH 80 int readbuff(char* buff) { size_t i=0; int c; //c=getchar(); while(i<MINLENGTH) { c=getchar(); if(c==EOF) return -1; if(c=='\n') return 0; buff[i++]=c; } return 1; } int copyline(char* buff) { size_t i; int c; int status = 1; for(i=0;i<MINLENGTH;i++) //数组buff存储前80个字符 putchar(buff[i]); while(status==1)//之后用getchar()和putchar()方法来输入输出大于80的字符 { c=getchar(); if(c==EOF) status=-1; else if (c=='\n') status=0; else putchar(c); } putchar('\n'); return status; } int main() { char buffer[MINLENGTH]; int status =0;//status用于记录输入的状态 while(status != -1){//status等于-1时,遇到EOF,退出while循环 status = readbuff(buffer); if(status==1)//status==1时, status = copyline(buffer); } return 0; }