Removing duplicates from an array of pointers
From: Bert (maatjesharing_at_gmx.de)
Date: 06/29/04
- Next message: Jerry Coffin: "Re: no match for complain"
- Previous message: Francis Glassborow: "Re: no match for complain"
- Next in thread: Rufus V. Smith: "Re: Removing duplicates from an array of pointers"
- Reply: Rufus V. Smith: "Re: Removing duplicates from an array of pointers"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 29 Jun 2004 04:07:59 -0700
I want to remove duplicate strings from an array of pointers to
strings.
Assume we have an array of pointers called "parray" of variable
length. The pointers point to the contents of a file which is read
into memory ("sfile"). Strings are created by replacing end of line
characters with nuls. An array of pointers (parray) points to the
first character of each line.
Suppose sfile contains this (can be another length or other content):
parray[0] AA
parray[1] DDD
parray[2] CC
parray[3] DDD
parray[4] EEEEEE
parray[5] FFFF
parray[6] DDD
If viewed as a flat memory area, it will look like this:
AA-DDD-CC-DDD-EEEEEE-FFFF-DDD- (- = '\0')
p0.p1..p2.p3..p4.....p5...p6..
The easy solution is to set the first character to NUL.
That would result in this memory area:
AA-DDD-CC--DD-EEEEEE-FFFF--DD-
p0.p1..p2.p3..p4.....p5...p6..
Two pointers (p3 and p6) now point to zero length strings. However,
zero length strings are unusuable for later operations.
What I'd like to get is this:
AA-DDD-CC--DD-EEEEEE-FFFF--DD-
p0.p1..p2.....p3.....p4.......
The order of the pointers isn't important.
I'm having trouble getting this done in real C code. Can anyone help?
Thanks!
Bert
- Next message: Jerry Coffin: "Re: no match for complain"
- Previous message: Francis Glassborow: "Re: no match for complain"
- Next in thread: Rufus V. Smith: "Re: Removing duplicates from an array of pointers"
- Reply: Rufus V. Smith: "Re: Removing duplicates from an array of pointers"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|