how to find the longest line from a set of lines?

Sunday, July 6, 2014

The goal is finding the longest line from a set of lines entered by the user and then prints it. The program sends me an error , i think there is something wrong with strlen. what i want is finding the error and how i can fix it .



#include<stdio.h>
#include<stdlib.h>
include<string.h>

int max(int nCHALL[]);
main()
{
char *CHALL[20] ;
int i , n, nCHALL[20] , maxi;

printf("°° entrer le nombre des lignes que vous souhaitez °° (max=20)\n");
scanf("%d",&n);
printf("entrer les linges que vous souhaitez :) \n");
for(i=0;i<n;i++)
{
scanf("%s",&CHALL[i]);
printf("\n");
}
for(i=0;i<n;i++)
{
nCHALL[i]=strlen(*CHALL[i]) ;
}
maxi=max(nCHALL[20]);
printf("la ligne la plus long est : ''%s''",CHALL[maxi]);



return 0 ;
}
int max(int nCHALL[])
{
int i ,j , maxi , nl ;
for(i=0;i!=0;i++)
{
for(j=0;j!=0;j++)
{if(nCHALL[i]<nCHALL[i+j+1])
{
maxi=nCHALL[i+j+1];
nl=j+1+i ;
}
else{maxi=nCHALL[i];
nl=i ;}
}
}
return nl;
}






http://ift.tt/1m5nDUd