Hi,
I wrote the following program:
#include <stdio.h>
#include <stdlib.h>
#define TRUE = 1;
#define FALSE = 0;
static int *arr;
static int size=0;
void createSet()
{
arr= (int *)malloc(sizeof(int));
size=0;
}/*createSet function*/
void putInSet(int num)
{
int *temp;
size++;
temp=(int *)realloc(arr,size*sizeof(int));
if(temp!=NULL)
{
arr=temp;
}
else
{
printf("Insufficient amount of free memory space !\nProgram will exit now.");
exit(1);
}
*(arr+size-1)=num;
}/*putInSet function*/
void printSet()
{
int i;
for(i=0 ; i<size ; i++)
{
printf(i<size-1 ?"%d ":"%d\n",arr[i]);
}
}/*printSet function*/
int existInSet(int num)
{
int status=FALSE;
int i=0;
for(i=0 ; i<size ; i++)
if(arr[i] == num)
status=TRUE;
return status;
}/*existInSet function*/
void freeSetMem()
{
free(arr);
}/*freeSetMem function*/
int main()
{
int num;
createSet();
while(scanf("%d",&num)==1)
{
if(!existInSet(num))
{
putInSet(num);
}
}
printSet();
freeSetMem();
return 0;
}/*main function*/
The error I got says:
my_set.c: In function ‘existInSet’:
my_set.c:45:13: error: expected expression before ‘=’ token
my_set.c:50:11: error: expected expression before ‘=’ token
I really don't understand where is my problem on this function...
Thanks !