char *ar[5]; //Array of pointers
let say char * ar[5] contain:
ar[0] = "cat";
ar[1] = "desk";
ar[2] = "desk"
ar[3] = "zoo";
ar[4] = "cat";
how i want to get of any same strings. so in end ar should have the value "cat","desk","zoo".
this is what i have so far but iam not sure if iam doing this right.
for(i = 0; i < 5; i++)
{
for(j = i+1; j < 5; i++)
{
if(ar[i] == ar[j])
{
ar[i] = '\0';
}
}
}
//print
for(i = 0; i < 5; i++)
{
printf("%s",ar[i]);
}
hwoarang69
11
Newbie Poster
Recommended Answers
Jump to PostYou can't use
if(ar[i] == ar[j])
because that is testing if the pointer values are equal not if the string are equal. You need to useif ( strcmp(ar[i],ar[j]) == 0 )
to check if two strings are equal. Ifstrcmp
return 0 they are equal. Also …
All 4 Replies
histrungalot
32
Junior Poster
hwoarang69
11
Newbie Poster
histrungalot
32
Junior Poster
hwoarang69
11
Newbie Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.