Hi,
I have written a function that removes double entries from a sorted
array.
See the structures
typedef struct tagRECR
{
char name[LEN_NAME+1];
}
REC;
// the REC structure is filled dynamic (malloc...)
typedef struct tagTAB
{
int count; // count of itemes in lief
REC *lief; // dynamic generated list
// belegte anz Eintr,,ge
}
TAB;
Now the function
void removedoubleentries( TAB *tab )
{
int i,j;
RECL *source;
RECL *dest;
BOOL found;
source = tab->lief;
dest = source;
j=0;
found = FALSE;
for (i = 0; i < tab->count-1; i ++ )
{
if ( strcmp ( (source+i)->name, (source+1+i)->name) !=0 )
{
*(dest+j) = *(source+i);
j++;
found = FALSE;
}
else
found = TRUE;
}
// Now I am not sure if this is correct
// for the last entrie
*(dest+j) = *(source+i);
j++;
tab->count = j;
}
ebc 6 2936
ebc wrote: I have written a function that removes double entries from a sorted array.
See the structures typedef struct tagRECR { char name[LEN_NAME+1];
} REC; // the REC structure is filled dynamic (malloc...) typedef struct tagTAB { int count; // count of itemes in lief REC *lief; // dynamic generated list // belegte anz Eintr,,ge } TAB;
Now the function
void removedoubleentries( TAB *tab ) { int i,j; RECL *source; RECL *dest; BOOL found;
source = tab->lief; dest = source;
j=0; found = FALSE;
for (i = 0; i < tab->count-1; i ++ ) { if ( strcmp ( (source+i)->name, (source+1+i)->name) !=0 ) { *(dest+j) = *(source+i); j++; found = FALSE; } else found = TRUE; } // Now I am not sure if this is correct // for the last entrie *(dest+j) = *(source+i); j++; tab->count = j;
}
Why not use ordinary array notation; `dest[j] = source[i]' etc?
August
ebc wrote: Hi,
I have written a function that removes double entries from a sorted array.
Please state what you are looking for
- a code review?
- finding the solution of a problem/if yes, which problem?
See the structures typedef struct tagRECR { char name[LEN_NAME+1];
} REC; // the REC structure is filled dynamic (malloc...) typedef struct tagTAB { int count; // count of itemes in lief
I would rather use size_t instead of int -- the guaranteed upper
bound of int is 32K-1...
REC *lief; // dynamic generated list // belegte anz Eintr,,ge } TAB;
Now the function
void removedoubleentries( TAB *tab ) { int i,j; RECL *source; RECL *dest;
The type RECL is not defined.
BOOL found;
The type BOOL is not defined.
Please do not post as-if-code but copies of the real thing. source = tab->lief; dest = source;
j=0; found = FALSE;
What do you need found for?
for (i = 0; i < tab->count-1; i ++ ) { if ( strcmp ( (source+i)->name, (source+1+i)->name) !=0 )
If you want to use pointers, use pointers, i.e. update source in
the loop update statement by source++ and
compare source->name and source[1].name/(source+1)->name.
Otherwise, use array index access as it is easier to read:
if ( strcmp(source[i].name, source[i+1].name) != 0 )
If you do not have many double first letters, you can speed up this
check:
if ( source[i].name[0] != source[i+1].name[0]
|| strcmp(source[i].name, source[i+1].name) != 0 ) { *(dest+j) = *(source+i); j++;
with pointer arithmetics
*(dest++) = *source;
(parentheses not necessary).
Part array/part pointer:
*dest++ = source[i];
found = FALSE; } else found = TRUE; } // Now I am not sure if this is correct // for the last entrie *(dest+j) = *(source+i);
Have you tried it?
j++; tab->count = j;
}
Why don't you give us something that compiles and tell us
your problem?
Note: Uppercase name are traditionally used for macros -- I
would rather not use them for typedefs.
Cheers
Michael
--
E-Mail: Mine is an /at/ gmx /dot/ de address.
cannot catch wot you mean
In article <11*********************@g44g2000cwa.googlegroups. com>,
<un**********@gmail.com> wrote: cannot catch wot you mean
ITYM:
cannut ketch wt u mn
On 2 Aug 2005 07:43:47 -0700, "ebc" <ce****@gmx.at> wrote: Hi,
I have written a function that removes double entries from a sorted array.
See the structures typedef struct tagRECR { char name[LEN_NAME+1];
} REC; // the REC structure is filled dynamic (malloc...) typedef struct tagTAB { int count; // count of itemes in lief REC *lief; // dynamic generated list // belegte anz Eintr,,ge } TAB;
Now the function
void removedoubleentries( TAB *tab ) { int i,j; RECL *source;
What is a RECL?
RECL *dest; BOOL found;
source = tab->lief;
source is a RECL*. tab->lief is a REC*. This is a syntax error
unless one of them is a synonym for void* and we know REC* is not.
Why don't you show us your real code? Use cut and paste; don't
retype.
dest = source;
j=0; found = FALSE;
This value will survive only if tab->count <= 1. for (i = 0; i < tab->count-1; i ++ ) { if ( strcmp ( (source+i)->name, (source+1+i)->name) !=0 )
source[i].name saves a couple of keystrokes and is easier on the eyes.
{ *(dest+j) = *(source+i);
As is dest[j].
j++; found = FALSE;
What is found used for?
} else found = TRUE; } // Now I am not sure if this is correct // for the last entrie *(dest+j) = *(source+i); j++;
Only if the above copy is performed. Maybe you should be using found
here. But watch out if tab->count is 0.
tab->count = j;
}
ebc
<<Remove the del for email>>
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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Sam Collett |
last post by:
How do I remove an item with a specified value from an array?
i.e. array values 1,2,2,5,7,12,15,21
remove 2 from array would return
1,5,7,12,15,21
(12 and 21 are NOT removed, duplicates are...
|
by: Lyle Fairfield |
last post by:
d1 and d2 are numbers we can store as doubles (8 bytes).
d1 > 0
d2 > 0
d1 < d2
Now s1 and s2 are strings of length 8 bytes. (We can ignore unicode here).
Into s1 and s2 we copy the 8 bytes...
|
by: Mamatha |
last post by:
Hi
I have an application with listview.When i click on one
button the data will be displayed like this in the
listview:
colA colB colC
----- ----- ------...
|
by: Niyazi |
last post by:
Hi all,
I have a dataTable that contains nearly 38400 rows.
In the dataTable consist of 3 column.
column 1 Name: MUHNO
column 2 Name: HESNO
Column 3 Name: BALANCE
Let me give you some...
|
by: pamelafluente |
last post by:
Hi
I have a sorted list with several thousands items. In my case, but this
is not important, objects are stored only in Keys, Values are all
Nothing. Several of the stored objects (might be a...
|
by: ericnyc |
last post by:
This is my second request. Some how I wrote the first problem I posted.
In this assignment I need to
print out the sorted array with say 10 entries per line
and then Finally it should print out...
|
by: Beholder |
last post by:
I hope that someone can help me with the following:
Short background explenation:
I have a shrfepoint page (newform.aspx) in a item list. On this page is
a lookup column that displays a lookup...
|
by: Sheldon |
last post by:
Hi,
I am trying to understand linked lists and the different ways to write
a linked list and double linked list. I have been trying to get this
function called insert_word to work but to no...
|
by: laredotornado |
last post by:
Hi,
I'm using PHP 5. I have an array of strings. What is the simplest
way to remove the elements that are empty, i.e. where the expression
"empty($elt)" returns true?
Thanks, - Dave
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
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,...
|
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...
| |