Hey hi all! i am reading The C Programming Lenguage, doing the exercies and i need some help
Exercise 1-17. Write a program to print all input lines that are longer than 80 characters.
Code:
#include <stdio.h>
#define MIN 2 /* print lines longer than this one */
#define MAXLENGHT 10000 /* the main arrays where all the lines will we saved */
#define MAXLINE 1000 /* mac line length */
int getline(char s[], int lim);
void copy_to_lines(char from[], char to[], int position, int len);
int strlen(char s[]);
int main()
{
char line[MAXLINE];
char lines_saved[MAXLENGHT];
int current_position = 0;
int len;
while(( len = getline(line, MAXLINE)) > 0)
{
if (len > MIN) {
copy_to_lines(line, lines_saved, current_position, len);
current_position += len;
}
}
printf("%s", lines_saved);
return 0;
}
int getline(char s[], int lim)
{
int c, i;
for (i = 0; i < lim && (c = getchar()) != EOF && c != '\n'; ++i)
{
s[i] = c;
}
if (c == '\n') {
s[i] = c;
++i;
}
return i;
}
void copy_to_lines(char from[], char to[], int position, int len)
{
int i;
for(i = 0; i < len; ++i)
{
to[position] = from[i];
++i;
++position;
}
}
I am not using any resource not present in the book at that point.
Any help is much appreciated.
Thanks.