I made a program to delete duplicates in an array but the program's if condition always remain true. I understood what the problem was,changed arr[i] to arr[count] and allocated memory via malloc,but the program prints the array as it is without deleting the duplicates.
# include<stdio.h>
# include<stdlib.h>
int count=0;
void Delete(int *arr);
void Search(int *arr);
int main()
{
int i;
int *arr;
arr=(int*)malloc(sizeof(int));
clrscr();
printf("Enter array and press -1 to stop:\n");/*stops when -1 occurs*/
for(count=0; ;count++)/*count is the count of the numbers*/
{
scanf("%d",&arr[count]);
realloc(arr,sizeof((int)+count));
fflush(stdin);
if(*(arr+count)==-1)/*This condition is never true.*/
break;
}
Search(arr);
for(i=0;i<count;i++)
{
printf("%d\t",arr[i]);
}
getch();
return 0;
}
Search(arr);
for(i=0;i<count;i++)
{
printf("%d",&arr[i]);
}
getch();
return 0;
}