seventeenth exercise - not sure about this one
This commit is contained in:
parent
a60014d7fa
commit
82ef6e9888
|
@ -0,0 +1,37 @@
|
||||||
|
#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-1){
|
||||||
|
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);
|
||||||
|
printf("%s\n", longline);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
Loading…
Reference in New Issue