Finding unique elements in an string array in C

Posted by LuckySlevin on Stack Overflow See other posts from Stack Overflow or by LuckySlevin
Published on 2010-05-10T16:40:44Z Indexed on 2010/05/10 16:44 UTC
Read the original article Hit count: 254

Filed under:
|
|
|

Hi,

C bothers me with its handling of strings. I have a pseudocode like this in my mind:

char *data[20];

char *tmp; int i,j;

for(i=0;i<20;i++) {

 tmp = data[i]; 

for(j=1;j<20;j++)

{ if(strcmp(tmp,data[j]))//then except the uniqueness, store them in elsewhere. } }

But when i coded this the results were bad.(I handled all the memory stuff,little things etc.) The problem is in the second loop obviously :D. But i cannot think any solution. How do i find unique strings in an array.

Example input : abc def abe abc def deg entered unique ones : abc def abe deg should be found.

© Stack Overflow or respective owner

Related posts about arrays

Related posts about string