Imagine, that I gave you a bushel of apples, and requested you pick out the biggest one. How would you do that?
Maybe:
1) Look at the first apple you took out of the bushel basket
2) compare all the other apples, one at a time, to see if they're bigger.
3) If you found a bigger apple, that would become the new biggest apple that the others in the basket, would be compared to
Programming works the same way:
Code:
int longest;
i=0;
while((fscanf(fp, " %[^\n]s",StrArr[i])) > 0)
{
length = strlen(StrArr[i]);
if(i == 0)
longest = i;
else {
if(length > StrArr[longest]) {
longest = i;
}
} //end of else
printf("%s",StrArr[i++]);
} //end of while
printf("Longest line was %s, with length of %d\n",StrArr[longest], strlen(StrArr[longest]);
If you want to count the actual letters (as opposed to the letters and the spaces, as I have here, then you need to use a while or for loop, and "walk" down the row of StrArr[longest], counting as you go.