This is it:
Code:
#include <stdio.h>
#define MAXLINE 1000
int getline(char line[], int maxline);
void copy(char to[], char from[]);
main()
{
int len;
int max;
int line[MAXLINE];
int longest[MAXLINE];
max = 0;
while ((len = getline(line, MAXLINE)) > 0) {
printf("%d = %s", len, line);
if(len > max) {
max = len;
copy (longest, line);
}
}
if (max > 0)
printf("%s", longest);
return 0;
}
int getline(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;
++j;
}
s[j] = '\0';
return i;
}
void copy(char to[], char from[])
{
int i;
i = 0;
while((to[i] = from[i]) != '\0')
++i;
}
I preety much understand everything.But can anyone explain to me
line 33.The condition for lim-2.What does lim-2 mean.A bit detail would be nice.Cuz this is the piece of code i don't understand.
And its messing up my understanding of the other parts.
So if anyone could please. ![Smile](https://cboard.cprogramming.com/images/smilies/smile.png)
Thank you!