c_exercises/1-17.c

41 lines
850 B
C
Raw Normal View History

#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;
}
2022-11-09 07:19:41 -03:00
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);
2022-11-09 07:19:41 -03:00
if (len>80){
printf("%s\n", longline);
}
}
return 0;
}