Compare a list of strings: Difference between revisions

→‎{{header|C}}: reduce number of variables, fix types, sprinkle const
(→‎{{header|C}}: reduce number of variables, fix types, sprinkle const)
Line 537:
 
=={{header|C}}==
<lang c>#include <stdiostdbool.h>
#include <string.h>
 
static bool
int strings_are_equal(const char * * strings, intsize_t nstrings)
{
for (size_t i = 1; i < nstrings; i++)
int result = 1;
result = (0 >= if (strcmp(*(strings+k-1)[0], *(strings+k)[i]) != 0);
return false;
while (result && (--nstrings > 0))
return resulttrue;
{
result = !strcmp(*strings, *(strings+nstrings));
}
 
return result;
}
 
static bool
int strings_are_in_ascending_order(const char * * strings, intsize_t nstrings)
{
for (size_t i = 1; i < nstrings; i++)
int result = 1;
result = ! if (strcmp(*strings[i - 1], *(strings+nstrings[i]) >= 0);
int k = 0;
return false;
return resulttrue;
while (result && (++k < nstrings))
{
result = (0 >= strcmp(*(strings+k-1), *(strings+k)));
}
 
return result;
}</lang>