Re: remove double entries from a sorted array



Thanks for reply all of you..

I have not just copy the original code because the variables are in
german. So for better reading i give you the code "translated" to
english.

First of all I' am looking if this could be work. I can not test it
yet.

-RECL is a syntax error it should be REC. -> re typing error :-)

<I would rather use size_t instead of int -- the guaranteed upper
bound of int is 32K-1... >
--> int is okay this array has a limit to 100 items. ( makes another
part of my program )

@Barry Schwarz and all others

I give you the original code

typedef struct tagRECLIEFNR
{
char vertrag[LEN_SAP_AUFTRAG+1];
char lieferscheinnr[LEN_SAP_LSCHEIN+1];
char liefText[LEN_SAP_LIEFTXT+1];
int stk;
}
RECLIEFNR;
typedef struct tagTABLIEFNR
{
int anz; // = counts of lief
int size; // Gr"áe Feld lief
RECLIEFNR *lief; // dynamic Filed with size size and count anz
}
TABLIEFNR;
static void RemoveDoppelteLSEintraege( TABLIEFNR *tsource )
{
int i,j;
RECLIEFNR *source;
RECLIEFNR *dest;

source = tsource->lief;
dest = source;

j=0;
i=0;
//found = FALSE;

if ( tsource->anz-1 < 0 )
return;

for (i = 0; i < tsource->anz-1; i ++ )
{
// no double entrie
if ( strcmp ( (source+i)->lieferscheinnr,
(source+1+i)->lieferscheinnr) != 0 )
{
*(dest+j) = *(source+i);
j++;
//found = FALSE;
}

}
// for the last entrie
*(dest+j) = *(source+i);
j++;
tsource->anz = j;

}
The problem with the anz < 1 should be now no problem.

Will this code work ?

And i know that this style *(dest+j) is'nt the best. I will change it
when i have time.

Thanks a lot

ebc

.



Relevant Pages

  • Re: Problems with mex file (allocating memory? )
    ... Here is a section of your original code you posted: ... int *maxNoOfPhotons; ... Or should you just return to MATLAB at that point with an error message? ...
    (comp.soft-sys.matlab)
  • Re: Explain why this prints the same
    ... > his original code and cleaned it up, but I am still wondering about ... lying to the compiler. ... Here the result is certain to be undefined behaviour. ...
    (comp.lang.c)
  • Re: [PATCH UPDATED] percpu: use dynamic percpu allocator as the default percpu allocator
    ... unsigned long flags; ... int off; ... Why don't we rewrite this as: ... actual difference between the original code and yours. ...
    (Linux-Kernel)
  • Re: goto
    ... is no guarantee that it (or the original code) is correct. ... I've never heard an objection to them. ... int getStdI ...
    (comp.lang.c)
  • Re: goto
    ... Here is a rewrite that eliminates the gotos and the "silly" macros. ... is no guarantee that it (or the original code) is correct. ... int getStdI ...
    (comp.lang.c)

Loading