Hi ,
Could you please help me whith this error?
:86:16: error:
invalid operands to binary == (have ‘IP_addres’ and ‘IP_addres’)
Code:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
typedef struct
{
long l;
union
{
unsigned int lo:16;
unsigned int hi:16;
}s;
}IP_addres;
typedef struct Node
{
IP_addres data;
struct Node *next;
} Node;
Node *HashTable[10];
// Function //
void create_hashtable(Node *HashTable[]) // create_hashtable Init
{
int index;
for(index=0;index<10;index++)
{
HashTable[index]=NULL;
}
}
Node* InsertNode(IP_addres Data) //hashtable_insert
{
Node *first;
Node *second;
int index;
first = (Node *) malloc(sizeof(Node));
if (first== 0)
{
printf ( "out of memory \n");
return(NULL);
}
if (HashTable[index] == NULL)
{
HashTable[index]=first;
first->next=NULL;
first->data=Data;
}
else
{
second=HashTable[index];
first->next=second;
first->data=Data;
}
return first;
}
void hashtable_remove(IP_addres Data) //hashtable_remove
{
Node *head;
Node *first=head;
Node *second=head;
if(head==NULL)
printf("first element is empty\n");
if(head->data==Data)
{
first=head->next;
free(head);
}
while(first->next!=NULL)
{
second=first;
first=first->next;
if(first->data==Data)
{
second->next=first->next;
free(second);
}
}
}
int hashtable_count(Node *node)
{
int i=0;
while(node!=NULL)
{
node=node->next;
i++;
}
printf("%d\n",i);
return i;
}
void menu()
{
{
puts("------------------------");
puts("r. hashtable_remove");
puts("i. InsertNode");
puts("c. hashtable_count");
puts("x. Exit");
}
}
int main(void) {
IP_addres IP;
char c;
Node *first;
create_hashtable(HashTable);
while(1)
{
start: menu();
printf("Enter IP Address:\n");
scanf("%x",&IP);
c = getchar();
switch(c)
{
case 'c': /* hashtable_count*/
hashtable_count( first);
goto start;
break;
case 'i': /* InsertNode*/
InsertNode(IP);
goto start;
break;
case 'r': /* hashtable_remove */
hashtable_remove(IP);
goto start;
break;
case 'x': /* Exit */
break;
}
}
return 0;
}