c_exercises/1-17.c

41 lines
850 B
C

#include <stdio.h>
#define MAXLINE 1000 /* maximum input line length */
/* ggetline: read a line into 'line', return length */
int ggetline(char line[], int maxline){
int c, i;
for (i=0; (c=getchar()) != EOF && c!='\n'; i++){
if(i<maxline-2){
line[i]=c;
}
else if(i==maxline-2){
line[i]='\n';
line[i++]='\0';
return i;
}
}
line[i]='\0';
return i;
}
/* copy: copy 'from' into 'to'; asume to is big enough */
void copy(char to[], char from[]){
int i;
i = 0;
while((to[i] = from[i]) != '\0'){
++i;
}
}
int main(){
int len; /* current line length */
char line[MAXLINE]; /* current input line */
char longline[MAXLINE]; /* line to print */
while ((len = ggetline(line, MAXLINE)) >0){
copy(longline, line);
if (len>80){
printf("%s\n", longline);
}
}
return 0;
}