Y
yogeshmk
I'm trying to write a program which sorts the strings entered by user.
I run it as
$./srt -sa dddd a ccc bb # -sa is options to the program s-string
a-ascending
and expect
a
bb
ccc
dddd
as output, for which I am using qsort() alongwith strcmp. However the
code simply prints back the strings as entered by user. I'm unable to
figure out what's wrong with the call to qsort().
Also when I compile the program, I get a warning saying something like
"argument 4 to qsort is of incompatible type" (not verbatim , I forgot
the actual message)
Here is a fragment of the code..
char **s = NULL;
</snip>
/*
*After stepping over argv[0], argv[1] (& possibly argv[2]), input
begins from argv
*/
s = argv+i;
if (option == STR)
{
qsort((void **) s, 0, argc-i,
(int(*)(char**, char**)) strcmp );
/* I have also tried (void*, void*)strcmp above, but get same
warning/output */
for (k=0; *(s+k); k++)
{
puts(*(s+k));
}
}
</snip>
I need help in figuring out what's wrong with qsort() call.
~yogesh
I run it as
$./srt -sa dddd a ccc bb # -sa is options to the program s-string
a-ascending
and expect
a
bb
ccc
dddd
as output, for which I am using qsort() alongwith strcmp. However the
code simply prints back the strings as entered by user. I'm unable to
figure out what's wrong with the call to qsort().
Also when I compile the program, I get a warning saying something like
"argument 4 to qsort is of incompatible type" (not verbatim , I forgot
the actual message)
Here is a fragment of the code..
char **s = NULL;
</snip>
/*
*After stepping over argv[0], argv[1] (& possibly argv[2]), input
begins from argv
*/
s = argv+i;
if (option == STR)
{
qsort((void **) s, 0, argc-i,
(int(*)(char**, char**)) strcmp );
/* I have also tried (void*, void*)strcmp above, but get same
warning/output */
for (k=0; *(s+k); k++)
{
puts(*(s+k));
}
}
</snip>
I need help in figuring out what's wrong with qsort() call.
~yogesh