30 Jul, 2015, arholly wrote in the 1st comment:
Votes: 0
Hi there:
I want to figure out what is the longest name in array I have. What's a good way to do that? I'm looking for the longest name in this (feat_list.name).

Thanks in advance for pointing me in the right direction.
30 Jul, 2015, quixadhal wrote in the 2nd comment:
Votes: 0
Well, since C uses NUL terminated strings, the only way to find the length of a string is to traverse it (using strlen(), which is optimized as much as possible). And, since your array isn't already sorted by length, you pretty much have to check every element in the array. So, the simplest way is probably the fastest way too.

int find_max_namelen( const char *names, const int elements_in_array ) {
int maxlen = 0;
int maxelement = 0;
for(i = 0; i < elements_in_array; i++) {
if( sl = strlen(names[i]) > maxlen ) {
maxlen = sl;
maxelement = i;
}
}
return maxelement;
}


Since you're using a structure of some sort, you'd pass in feat_list instead, and compare strlen(feat_list.name)… but given what you wrote, it sounds like feat_list might not actually be an array. If it's a linked list, you'll have to traverse the list instead of using a loop. But DikuMUD's have a zillion places that do that as examples. :)
0.0/2