Program spośród wprowadzonych wierszy ma wybierać najdłuższy i wyświetlać go na końcu programu.
Problem leży gdzieś w funkcji getline - wg moich testów zwraca ona niepoprawną liczbę znaków w wierszu. Co jest nie tak?
#define MAXLINE 1000
#include <stdio.h>
int getlin(char tab[MAXLINE]);
void copy(char to[MAXLINE], char from[]);
int main()
{
char napis[MAXLINE];
char longest[MAXLINE]="a";
int max=0;
int len;
while(len=getlin(napis)>0)
{
if(len>max)
{
max=len;
copy(longest,napis);
}
//printf("%d",len);
}
printf("%s\n",longest);
}
int getlin(char tab[MAXLINE])
{
int i,c;
for(i=0; (c=getchar())!=EOF && c!='\n'; i++)
{
tab[i]=c;
printf("%c",tab++);
}
return i;
}
void copy(char to[MAXLINE], char from[MAXLINE])
{
int i;
for(i=0; from[i]!='\0'; i++)
{
to[i]=from[i];
}
to[i]='\0';
}