#include<stdio.h>#define MAXLINE 1000 /*maximum input line size*/intgetlines(char line[],int maxline);voidcopy(char to[],char from[]);/* print longest input line*/intmain(){int len;/* current line length */int max;/* maxinum length seen so far */char line[MAXLINE];/* current input line */char longest[MAXLINE];/* longest line saved here */
max =0;while((len =getlines(line, MAXLINE))>0){printf("%d %s", len, line);if(len > max){
max = len;copy(longest, line);}}if(max >0){/* there was a line*/printf("%s", longest);}return0;}/* getline: read a line into s, return length */intgetlines(char s[],int lim){int c, i, j;
j =0;for(i =0;(c =getchar())!=EOF&& c !='\n'; i++){if(i < lim -2){
s[j]= c;++j;}}if(c =='\n'){
s[j]= c;++i;++j;}
s[j]='\0';return i;}/* copy: copy 'from' into 'to'; assume to is big enough */voidcopy(char to[],char from[]){int i =0;while((to[i]= from[i])!='\0'){++i;}}
1.17
/* 第一种解法 */#define _GNU_SOURCE#include<stdio.h>#include<stdlib.h>#define EIGHTY 80intmain(){char*line =NULL;
size_t len =0;
size_t read =0;while((read =getline(&line,&len,stdin))>1){if(read > EIGHTY){printf("%s\n", line);}
read =0;}return0;}/* 第二种解法 */#define _GNU_SOURCE#include<stdio.h>#define MAXLINE 1000 /* maximum input line size */#define LONGLINE 80intgetlines(char s[],int lim);/* print line longer than LONGLINE */intmain(){int len;/* current line length */char line[MAXLINE];/* current input line */while((len =getlines(line, MAXLINE))>0){if(len > LONGLINE){printf("%s", line);}}return0;}/* getline: read a line into s, return length */intgetlines(char s[],int lim){int c, i, j;
j =0;for(i =0;(c =getchar())!=EOF&& c !='\n'; i++){if(i < lim -2){
s[j]= c;++j;}}if(c =='\n'){
s[j]= c;++i;++j;}
s[j]='\0';return i;}
1.19
/* 第一种解法 */#include<stdio.h>voidprintReverse(){int c;
c =getchar();if(c =='\n'){return;}else{printReverse();putchar(c);}}intmain(){printReverse();printf("\n");return0;}/* 第二种解法 */#include<stdio.h>#define MAXLINE 1000 /* maxinum input line size */intgetlines(char line[],int maxline);voidreverse(char s[]);/* revserse input lines, a line at a time */intmain(){char line[MAXLINE];/* current input line */while(getlines(line, MAXLINE)>0){reverse(line);printf("%s", line);}return0;}/*reverse: reverse string s*/voidreverse(char s[]){int i, j;char tmp;
i =0;while(s[i]!=0){/* find the end of string s */++i;}--i;/* back off from '\0' */if(s[i]=='\n'){--i;/* leave newline in place */}
j =0;/* beginning of new string s */while(j < i){
tmp = s[j];
s[j]= s[i];
s[i]= tmp;--i;
j++;}}/* getline: read a line into s, return length */intgetlines(char s[],int lim){int c, i, j;
j =0;for(i =0;(c =getchar())!=EOF&& c !='\n'; i++){if(i < lim -2){
s[j]= c;++j;}}if(c =='\n'){
s[j]= c;++i;++j;}
s[j]='\0';return i;}