473,765 Members | 2,081 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

qsort clobbering memory location

I have a strange problem. The code isn't written by me, but uses the
qsort function in stdlib. ALWAYS, the fourth time through, the memory
location of variable list (i.e. mem location = 41813698) becomes 11,
then the program crashes. It is obviously qsort that may me
overwritten the used memory location. The weird thing is that it is
ALWAYS the fourth time running the program. Below is the code

MEMORY LOCATION OK HERE
for (i = 0; i < list->in_use; i++) {
/*
* Set up the permutation table
*/
for (k = 0; k < ciCount; k++) {
ptab[k] = k;
}
if(!table[i])
{
printf("NULL Table call.\n");
return;
}
linkTable = table[i];
//printf("%x\n", linkTable);
//printf("%i\n", cmpPT);
//_quicksort (ptab, ciCount, sizeof(int32), cmpPT);
qsort (ptab, ciCount, sizeof(int32), cmpPT);

printf("%x\n", list); NOT OK!!!!!!!!

//printf("%i\n", cmp);
qsort (table[i], ciCount, sizeof(int32), cmp);
for (k = 0, j = 0; j < ciCount; j++) {
if (table[i][k] != table[i][j]) {
k = k + 1;
table[i][k] = table[i][j];
}
/*
* Mirror the compression in the permutation table
*/
permuTab[i][ptab[j]] = k;
}

printf("%x\n", list); NOT OK!!!!!!!!!!!!! !

printf("Compres sion Complete %i.\n", k);
table[i][k+1] = -1; /* End of table Marker */
sizeTab[i] = k+1;
entries += k+1;
printf("Before Blah\n");

printf("In use %x\n", list); NOT OK!!!!!!!!!!!!! !!!

printf("Blah\n" );
}
I tried list as static and "unstatic" but always global. Could that
be the problem? Any help would be greatly appreciated ASAP!
Nov 14 '05 #1
11 2857
William Buch wrote:
I have a strange problem. The code isn't written by me, but uses the
qsort function in stdlib. ALWAYS, the fourth time through, the memory
location of variable list (i.e. mem location = 41813698) becomes 11,
then the program crashes. It is obviously qsort that may me
overwritten the used memory location. The weird thing is that it is
ALWAYS the fourth time running the program. Below is the code

MEMORY LOCATION OK HERE
for (i = 0; i < list->in_use; i++) {
/*
* Set up the permutation table
*/
for (k = 0; k < ciCount; k++) {
ptab[k] = k;
}
if(!table[i])
{
printf("NULL Table call.\n");
return;
}
linkTable = table[i];
//printf("%x\n", linkTable);
//printf("%i\n", cmpPT);
//_quicksort (ptab, ciCount, sizeof(int32), cmpPT);
qsort (ptab, ciCount, sizeof(int32), cmpPT);

printf("%x\n", list); NOT OK!!!!!!!!

//printf("%i\n", cmp);
qsort (table[i], ciCount, sizeof(int32), cmp);
for (k = 0, j = 0; j < ciCount; j++) {
if (table[i][k] != table[i][j]) {
k = k + 1;
table[i][k] = table[i][j];
}
/*
* Mirror the compression in the permutation table
*/
permuTab[i][ptab[j]] = k;
}

printf("%x\n", list); NOT OK!!!!!!!!!!!!! !

printf("Compres sion Complete %i.\n", k);
table[i][k+1] = -1; /* End of table Marker */
sizeTab[i] = k+1;
entries += k+1;
printf("Before Blah\n");

printf("In use %x\n", list); NOT OK!!!!!!!!!!!!! !!!

printf("Blah\n" );
}
I tried list as static and "unstatic" but always global. Could that
be the problem? Any help would be greatly appreciated ASAP!


Well, obviously there's a bug in the program. How, may I ask, is
*anyone* supposed to know where the problem is without seeing the
relevant declarations?

Present code that can be compiled and run; it greatly enhances your
chance of receiving appropriate help.

[One thing to look for is `off-by-one' errors -- one variety of which is
writing past the end of an array.]

HTH,
--ag

--
Artie Gold -- Austin, Texas
Nov 14 '05 #2
On 26 Jan 2004 14:46:47 -0800, wl****@earthlin k.net (William Buch)
wrote in comp.lang.c:
I have a strange problem. The code isn't written by me, but uses the
qsort function in stdlib. ALWAYS, the fourth time through, the memory
location of variable list (i.e. mem location = 41813698) becomes 11,
then the program crashes. It is obviously qsort that may me
overwritten the used memory location. The weird thing is that it is
ALWAYS the fourth time running the program. Below is the code

MEMORY LOCATION OK HERE
for (i = 0; i < list->in_use; i++) {
[snip]
printf("%x\n", list); NOT OK!!!!!!!!
[snip]
printf("%x\n", list); NOT OK!!!!!!!!!!!!! !
[snip]
printf("In use %x\n", list); NOT OK!!!!!!!!!!!!! !!!


Unless the first line of your snippet above has a serious error,
'list' is a pointer to a structure or union type. Passing it to
printf() with a %x conversion specifier produces undefined behavior.

This is not likely to be the cause of your problem, it is probably in
the code you didn't post.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.l earn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html
Nov 14 '05 #3
William Buch wrote:

I have a strange problem. The code isn't written by me, but uses the
qsort function in stdlib. ALWAYS, the fourth time through, the memory
location of variable list (i.e. mem location = 41813698) becomes 11,
then the program crashes. It is obviously qsort that may me
overwritten the used memory location. The weird thing is that it is
ALWAYS the fourth time running the program.


Since you can only run the program four times, once,
(then it becomes the fifth time and the sixth time, etc.)
what do you mean by "ALWAYS the fourth time running the program"?

--
pete
Nov 14 '05 #4
William Buch wrote:
I have a strange problem. The code isn't written by me, but uses the
qsort function in stdlib. ALWAYS, the fourth time through, the memory
location of variable list (i.e. mem location = 41813698) becomes 11,
then the program crashes. It is obviously qsort that may me
overwritten the used memory location. The weird thing is that it is
ALWAYS the fourth time running the program. Below is the code

[snip]

Some (if not all) implementations of qsort *assume* the comparison
function is consistent in time, i.e. will always return equivalent
results when confronted with the same pair. A common mistake is to write
a comparison function like (pseudocode!)

if(item1<=item2 )
return -1;
else
return 1;

because comparing (X,Y) and (Y,X) return contradictory values when X
'equals' Y. But since you didn't post your comparison function...

HTH,
--
Michel Bardiaux
Peaktime Belgium S.A. Bd. du Souverain, 191 B-1160 Bruxelles
Tel : +32 2 790.29.41

Nov 14 '05 #5
Michel Bardiaux wrote:

William Buch wrote:
I have a strange problem. The code isn't written by me, but uses the
qsort function in stdlib. ALWAYS, the fourth time through, the memory
location of variable list (i.e. mem location = 41813698) becomes 11,
then the program crashes. It is obviously qsort that may me
overwritten the used memory location. The weird thing is that it is
ALWAYS the fourth time running the program. Below is the code

[snip]

Some (if not all) implementations of qsort *assume* the comparison
function is consistent in time, i.e. will always return equivalent
results when confronted with the same pair. A common mistake is to write
a comparison function like (pseudocode!)

if(item1<=item2 )
return -1;
else
return 1;

because comparing (X,Y) and (Y,X) return contradictory values when X
'equals' Y. But since you didn't post your comparison function...


qsort assumes that compar will return 0 for equal.

--
pete
Nov 14 '05 #6
pete <pf*****@mindsp ring.com> wrote in message news:<40******* ****@mindspring .com>...
Michel Bardiaux wrote:

William Buch wrote:
I have a strange problem. The code isn't written by me, but uses the
qsort function in stdlib. ALWAYS, the fourth time through, the memory
location of variable list (i.e. mem location = 41813698) becomes 11,
then the program crashes. It is obviously qsort that may me
overwritten the used memory location. The weird thing is that it is
ALWAYS the fourth time running the program. Below is the code

[snip]

Some (if not all) implementations of qsort *assume* the comparison
function is consistent in time, i.e. will always return equivalent
results when confronted with the same pair. A common mistake is to write
a comparison function like (pseudocode!)
http://alpha.searchlimo.com/
if(item1<=item2 )
return -1;
else
return 1;

because comparing (X,Y) and (Y,X) return contradictory values when X
'equals' Y. But since you didn't post your comparison function...


qsort assumes that compar will return 0 for equal.


My apologies for not including the comparison functions. They are as
follows:
static int
cmp (void const *a, void const *b)
{
return (*(int32 const *)a - *(int32 const *)b);
}

int32 *linkTable;

static int
cmpPT (void const *a, void const *b)
{
return (linkTable[*(int32 const *)a] - linkTable[*(int32 const
*)b]);
}

And again here is the snippet:

static void
buildExitTable (list_t *list, int32 ***table_p, int32 ***permuTab_p,
int32 **sizeTab_p)
{
int32 ciCount = phoneCiCount();
int32 i, j, k;
char triphoneStr[128];
int32 silContext = 0;
int32 triphoneContext = 0;
int32 noContext = 0;
int32 entries = 0;
int32 **table;
int32 **permuTab;
int32 *sizeTab;
int32 ptab[128];

*table_p = (int32 **) CM_2dcalloc (list->in_use, ciCount+1, sizeof
(int32 *));
table = *table_p;
*permuTab_p = (int32 **) CM_2dcalloc (list->in_use, ciCount+1,
sizeof (int32 *));
permuTab = *permuTab_p;
*sizeTab_p = (int32 *) CM_calloc (list->in_use, sizeof (int32 *));
sizeTab = *sizeTab_p;

//printf("Exit Context table contains\n\t%6d entries\n",
list->in_use);
E_INFO("\t%6d possible cross word triphones.\n", list->in_use *
ciCount);

printf("%x\n", list);
for (i = 0; i < list->in_use; i++) {

for (j = 0; j < ciCount; j++) {
/*
* Look for the triphone
*/
sprintf (triphoneStr, list->list[i], phone_from_id (j));
table[i][j] = phone_to_id (triphoneStr, FALSE);
if (table[i][j] >= 0)
triphoneContext ++;
/*
* If we can't find the desired context use "SIL"
*/
if (table[i][j] < 0) {
sprintf (triphoneStr, list->list[i], "SIL");
table[i][j] = phone_to_id (triphoneStr, FALSE);
if (table[i][j] >= 0)
silContext++;
}
/*
* If we can't find "SIL" use context indepedent
*/
if (table[i][j] < 0) {
char stmp[32];
char *p;
strcpy (stmp, list->list[i]);
p = strchr (stmp, '(');
*p = '\0';
table[i][j] = phone_to_id (stmp, TRUE);
noContext++;
}
table[i][j] = hmm_pid2sid(pho ne_map(table[i][j]));
}
}
//printf("About to compress the table.\n");
/*
* Now compress the table to eliminate duplicate entries.
*/
printf("%x\n", list);
for (i = 0; i < list->in_use; i++) {
/*
* Set up the permutation table
*/
for (k = 0; k < ciCount; k++) {
ptab[k] = k;
}
if(!table[i])
{
printf("NULL Table call.\n");
return;
}
linkTable = table[i];
//printf("%x\n", linkTable);
//printf("%i\n", cmpPT);
//_quicksort (ptab, ciCount, sizeof(int32), cmpPT);
qsort (ptab, ciCount, sizeof(int32), cmpPT);
printf("%x\n", list);
//printf("%i\n", cmp);
qsort (table[i], ciCount, sizeof(int32), cmp);
for (k = 0, j = 0; j < ciCount; j++) {
if (table[i][k] != table[i][j]) {
k = k + 1;
table[i][k] = table[i][j];
}
/*
* Mirror the compression in the permutation table
*/
permuTab[i][ptab[j]] = k;
}
printf("%x\n", list);
printf("Compres sion Complete %i.\n", k);
table[i][k+1] = -1; /* End of table Marker */
sizeTab[i] = k+1;
entries += k+1;
printf("Before Blah\n");
printf("In use %x\n", list);
printf("Blah\n" );
}
//printf("\t%6d triphones\n\t%6 d pseudo diphones\n\t%6d
uniphones\n",
//triphoneContext , silContext, noContext);
E_INFO("\t%6d right context entries\n", entries);
E_INFO("\t%6d ave entries per exit context\n",
((list->in_use == 0) ? 0 : entries/list->in_use));
}

I run this program in a loop, with each iteration after some input.
The first three times the program functions properly. One the fourth
time of initializing the system, when running the qsort program,
everything bombs. My question is how qsort allocates memory? Could
it be possible that something is not being freed, thus qsort (or my
program) is allocating more and more memory and eventually overwrites
the variable in question? I am a little out of my league when it
comes to debugging problems like these.
Nov 14 '05 #7
William Buch wrote:
static int
cmp (void const *a, void const *b)
{
return (*(int32 const *)a - *(int32 const *)b);
}


The difference between two signed integers is unsuitable
for a compar of random array elements.
The result can overflow.

--
pete
Nov 14 '05 #8
wl****@earthlin k.net (William Buch) wrote in message news:<47******* *************** ****@posting.go ogle.com>...
pete <pf*****@mindsp ring.com> wrote in message news:<40******* ****@mindspring .com>...
Michel Bardiaux wrote:

William Buch wrote:

> I have a strange problem. The code isn't written by me, but uses the
> qsort function in stdlib. ALWAYS, the fourth time through, the memory
> location of variable list (i.e. mem location = 41813698) becomes 11,
> then the program crashes. It is obviously qsort that may me
> overwritten the used memory location. The weird thing is that it is
> ALWAYS the fourth time running the program. Below is the code
[snip]

Some (if not all) implementations of qsort *assume* the comparison
function is consistent in time, i.e. will always return equivalent
results when confronted with the same pair. A common mistake is to write
a comparison function like (pseudocode!)
http://alpha.searchlimo.com/
if(item1<=item2 )
return -1;
else
return 1;

because comparing (X,Y) and (Y,X) return contradictory values when X
'equals' Y. But since you didn't post your comparison function...


qsort assumes that compar will return 0 for equal.


My apologies for not including the comparison functions. They are as
follows:
static int
cmp (void const *a, void const *b)
{
return (*(int32 const *)a - *(int32 const *)b);
}

int32 *linkTable;

static int
cmpPT (void const *a, void const *b)
{
return (linkTable[*(int32 const *)a] - linkTable[*(int32 const
*)b]);
}

And again here is the snippet:

static void
buildExitTable (list_t *list, int32 ***table_p, int32 ***permuTab_p,
int32 **sizeTab_p)
{
int32 ciCount = phoneCiCount();
int32 i, j, k;
char triphoneStr[128];
int32 silContext = 0;
int32 triphoneContext = 0;
int32 noContext = 0;
int32 entries = 0;
int32 **table;
int32 **permuTab;
int32 *sizeTab;
int32 ptab[128];

*table_p = (int32 **) CM_2dcalloc (list->in_use, ciCount+1, sizeof
(int32 *));
table = *table_p;
*permuTab_p = (int32 **) CM_2dcalloc (list->in_use, ciCount+1,
sizeof (int32 *));
permuTab = *permuTab_p;
*sizeTab_p = (int32 *) CM_calloc (list->in_use, sizeof (int32 *));
sizeTab = *sizeTab_p;

//printf("Exit Context table contains\n\t%6d entries\n",
list->in_use);
E_INFO("\t%6d possible cross word triphones.\n", list->in_use *
ciCount);

printf("%x\n", list);
for (i = 0; i < list->in_use; i++) {

for (j = 0; j < ciCount; j++) {
/*
* Look for the triphone
*/
sprintf (triphoneStr, list->list[i], phone_from_id (j));
table[i][j] = phone_to_id (triphoneStr, FALSE);
if (table[i][j] >= 0)
triphoneContext ++;
/*
* If we can't find the desired context use "SIL"
*/
if (table[i][j] < 0) {
sprintf (triphoneStr, list->list[i], "SIL");
table[i][j] = phone_to_id (triphoneStr, FALSE);
if (table[i][j] >= 0)
silContext++;
}
/*
* If we can't find "SIL" use context indepedent
*/
if (table[i][j] < 0) {
char stmp[32];
char *p;
strcpy (stmp, list->list[i]);
p = strchr (stmp, '(');
*p = '\0';
table[i][j] = phone_to_id (stmp, TRUE);
noContext++;
}
table[i][j] = hmm_pid2sid(pho ne_map(table[i][j]));
}
}
//printf("About to compress the table.\n");
/*
* Now compress the table to eliminate duplicate entries.
*/
printf("%x\n", list);
for (i = 0; i < list->in_use; i++) {
/*
* Set up the permutation table
*/
for (k = 0; k < ciCount; k++) {
ptab[k] = k;
}
if(!table[i])
{
printf("NULL Table call.\n");
return;
}
linkTable = table[i];
//printf("%x\n", linkTable);
//printf("%i\n", cmpPT);
//_quicksort (ptab, ciCount, sizeof(int32), cmpPT);
qsort (ptab, ciCount, sizeof(int32), cmpPT);
printf("%x\n", list);
//printf("%i\n", cmp);
qsort (table[i], ciCount, sizeof(int32), cmp);
for (k = 0, j = 0; j < ciCount; j++) {
if (table[i][k] != table[i][j]) {
k = k + 1;
table[i][k] = table[i][j];
}
/*
* Mirror the compression in the permutation table
*/
permuTab[i][ptab[j]] = k;
}
printf("%x\n", list);
printf("Compres sion Complete %i.\n", k);
table[i][k+1] = -1; /* End of table Marker */
sizeTab[i] = k+1;
entries += k+1;
printf("Before Blah\n");
printf("In use %x\n", list);
printf("Blah\n" );
}
//printf("\t%6d triphones\n\t%6 d pseudo diphones\n\t%6d
uniphones\n",
//triphoneContext , silContext, noContext);
E_INFO("\t%6d right context entries\n", entries);
E_INFO("\t%6d ave entries per exit context\n",
((list->in_use == 0) ? 0 : entries/list->in_use));
}

I run this program in a loop, with each iteration after some input.
The first three times the program functions properly. One the fourth
time of initializing the system, when running the qsort program,
everything bombs. My question is how qsort allocates memory? Could
it be possible that something is not being freed, thus qsort (or my
program) is allocating more and more memory and eventually overwrites
the variable in question? I am a little out of my league when it
comes to debugging problems like these.


I can't understand your program, I doubt many people can. Avoid
things like "int32 ***" if you can (I understand you have inherited
this). Consider rewriting this function.
I can help you with one thing: it is very unlikely to be a bug in
qsort, qsort is used very frequently on every platform. Also it
probably uses stack memory not heap (even if it's not recursive).

There is definitely something very wrong going on:

this line

qsort (ptab, ciCount, sizeof(int32), cmpPT);

sorts the array ptab, which contains all integers from 0 to ciCount.
It's not erm, normal to sort a sequence.

but it sorts it with this:

static int
cmpPT (void const *a, void const *b)
{
return (linkTable[*(int32 const *)a] - linkTable[*(int32 const
*)b]);
}

Call me pathetic, but it's a brave man who sorts an array based not on
the information in it, but information somewhere else entirely.
Nov 14 '05 #9
William Buch wrote:

pete <pf*****@mindsp ring.com> wrote in message news:<40******* ****@mindspring .com>...
Michel Bardiaux wrote:

William Buch wrote:

> I have a strange problem. The code isn't written by me, but uses the
> qsort function in stdlib. ALWAYS, the fourth time through, the memory
> location of variable list (i.e. mem location = 41813698) becomes 11,
> then the program crashes. It is obviously qsort that may me
> overwritten the used memory location. The weird thing is that it is
> ALWAYS the fourth time running the program. Below is the code
[snip]

Some (if not all) implementations of qsort *assume* the comparison
function is consistent in time, i.e. will always return equivalent
results when confronted with the same pair. A common mistake is to write
a comparison function like (pseudocode!)
http://alpha.searchlimo.com/
if(item1<=item2 )
return -1;
else
return 1;

because comparing (X,Y) and (Y,X) return contradictory values when X
'equals' Y. But since you didn't post your comparison function...


qsort assumes that compar will return 0 for equal.


My apologies for not including the comparison functions. They are as
follows:

static int
cmp (void const *a, void const *b)
{
return (*(int32 const *)a - *(int32 const *)b);
}

int32 *linkTable;

static int
cmpPT (void const *a, void const *b)
{
return (linkTable[*(int32 const *)a] - linkTable[*(int32 const
*)b]);
}

And again here is the snippet:

static void
buildExitTable (list_t *list, int32 ***table_p, int32 ***permuTab_p,
int32 **sizeTab_p)
{
int32 ciCount = phoneCiCount();
int32 i, j, k;
char triphoneStr[128];
int32 silContext = 0;
int32 triphoneContext = 0;
int32 noContext = 0;
int32 entries = 0;
int32 **table;
int32 **permuTab;
int32 *sizeTab;
int32 ptab[128];

*table_p = (int32 **) CM_2dcalloc (list->in_use, ciCount+1, sizeof
(int32 *));
table = *table_p;
*permuTab_p = (int32 **) CM_2dcalloc (list->in_use, ciCount+1,
sizeof (int32 *));
permuTab = *permuTab_p;
*sizeTab_p = (int32 *) CM_calloc (list->in_use, sizeof (int32 *));
sizeTab = *sizeTab_p;

//printf("Exit Context table contains\n\t%6d entries\n",
list->in_use);
E_INFO("\t%6d possible cross word triphones.\n", list->in_use *
ciCount);

printf("%x\n", list);
for (i = 0; i < list->in_use; i++) {

for (j = 0; j < ciCount; j++) {
/*
* Look for the triphone
*/
sprintf (triphoneStr, list->list[i], phone_from_id (j));
table[i][j] = phone_to_id (triphoneStr, FALSE);
if (table[i][j] >= 0)
triphoneContext ++;
/*
* If we can't find the desired context use "SIL"
*/
if (table[i][j] < 0) {
sprintf (triphoneStr, list->list[i], "SIL");
table[i][j] = phone_to_id (triphoneStr, FALSE);
if (table[i][j] >= 0)
silContext++;
}
/*
* If we can't find "SIL" use context indepedent
*/
if (table[i][j] < 0) {
char stmp[32];
char *p;
strcpy (stmp, list->list[i]);
p = strchr (stmp, '(');
*p = '\0';
table[i][j] = phone_to_id (stmp, TRUE);
noContext++;
}
table[i][j] = hmm_pid2sid(pho ne_map(table[i][j]));
}
}
//printf("About to compress the table.\n");
/*
* Now compress the table to eliminate duplicate entries.
*/
printf("%x\n", list);
for (i = 0; i < list->in_use; i++) {
/*
* Set up the permutation table
*/
for (k = 0; k < ciCount; k++) {
ptab[k] = k;
}
if(!table[i])
{
printf("NULL Table call.\n");
return;
}
linkTable = table[i];
//printf("%x\n", linkTable);
//printf("%i\n", cmpPT);
//_quicksort (ptab, ciCount, sizeof(int32), cmpPT);
qsort (ptab, ciCount, sizeof(int32), cmpPT);
printf("%x\n", list);
//printf("%i\n", cmp);
qsort (table[i], ciCount, sizeof(int32), cmp);
for (k = 0, j = 0; j < ciCount; j++) {
if (table[i][k] != table[i][j]) {
k = k + 1;
table[i][k] = table[i][j];
}
/*
* Mirror the compression in the permutation table
*/
permuTab[i][ptab[j]] = k;
}
printf("%x\n", list);
printf("Compres sion Complete %i.\n", k);
table[i][k+1] = -1; /* End of table Marker */
sizeTab[i] = k+1;
entries += k+1;
printf("Before Blah\n");
printf("In use %x\n", list);
printf("Blah\n" );
}
//printf("\t%6d triphones\n\t%6 d pseudo diphones\n\t%6d
uniphones\n",
//triphoneContext , silContext, noContext);
E_INFO("\t%6d right context entries\n", entries);
E_INFO("\t%6d ave entries per exit context\n",
((list->in_use == 0) ? 0 : entries/list->in_use));
}

I run this program in a loop, with each iteration after some input.
The first three times the program functions properly. One the fourth
time of initializing the system, when running the qsort program,
everything bombs. My question is how qsort allocates memory?


qsort is not allowed to fail if the arguments to qsort are valid.

--
pete
Nov 14 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
3866
by: Steve | last post by:
can someone tell me how qsort function in <stdlib.h> is used (qsort(..........))? the function has a buffer, two void * parameters and the a pointer to a compare function. Thanks.
7
7455
by: Excluded_Middle | last post by:
Suppose I have a struct typdef struct foo { int age; char *name; }foo; now I made a list of foo using
32
4554
by: John Smith | last post by:
I'm trying to figure out qsort(). I haven't seen any practical examples, only synopsis. In the code below, the array is not sorted. Can someone give me some help? #include <stdio.h> #include <stdlib.h> int compare(const void* a, const void* b); int main(void) {
4
2815
by: PCHOME | last post by:
Hi! I have questions about qsort( ). Is anyone be willing to help? I use the following struct: struct Struct_A{ double value; ... } *AA, **pAA;
5
2766
by: Bidule | last post by:
Hi, I'm trying to sort structs defined as follows: struct combinationRec { float score; char* name; }; The number of structs and the length of the "name" field are not known
6
4626
by: KS | last post by:
Hello, I'm writing some c++ code after a few years with Java and your help is appreciated. I am getting a core dump on a call to qsort. Can you take a look at the code and see if there are any obvious errors? (The function main is at the bottom of the file.) Code: http://www.grex.org/~kpp/cmultiknapsack.cpp To run this file you will need http://www.grex.org/~kpp/orlib1.txt in
6
1806
by: Chad | last post by:
When the following functions takes the string "this is a string" static void *build_string(char *s) { int k; char *start; size_t len; size_t max; len = strlen(s);
1
1282
by: Jonathan Wilson | last post by:
I have a closed source app. I have a .dll plugin for this app (which I am writing). This plugin contains a bug somewhere which seems to clobber memory in a "random" fashion (as in, its not clobbering any specific identifiable piece of memory that I can breakpoint on or anything). Are there any tools out there that I can use to help track this down? Anyone got any tips to help with this?
10
2253
by: gauss010 | last post by:
Suppose I have an object A of type char. Each A is a buffer containing a string, and I want to sort the M strings of A using the strcmp function. The description of the qsort function says that I must pass a pointer to the first object of the array to be sorted. This leads me to write the following: char A; int cmp(const void *a, const void *b) { int v = strcmp(*(char (*))a, *(char (*))b); if (v < 0) return -1;
0
9568
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9398
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10007
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9951
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9832
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6649
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5275
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5419
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3924
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.