This is compiles ok
Code:
#include <stdlib.h>
#include <malloc.h>
#include <string.h>
#include <iostream.h>
struct data;
typedef struct data LIST;
typedef LIST *LINK;
struct data
{
char ip[20];
char user[30];
LIST *next ;
};
// Add user to the linked list
void adduser(char *ipaddr, char username[], LINK *first)
{
LINK newE;
LINK tmp;
LINK prev;
if ( (newE = (LINK)malloc(sizeof(LIST))) == NULL)
{
cout << "Not enough memory";
exit(0);
}
strcpy(newE->ip, ipaddr);
strcpy(newE->user, username);
if ( *first == NULL )
{
*first=newE;
newE->next=NULL;
}
else
{
tmp = (*first)->next;
prev=*first;
while( tmp->next != NULL )
{
newE->next = tmp;
if (newE->next != prev->next)
{
cout << "ERROR";
exit(0);
}
prev->next = newE;
}
if (tmp->next == NULL )
{
tmp->next = newE;
newE->next = NULL;
}
}
}
// Retrieve a user from the list
void getuser(char name[], char *ipaddr, LINK first)
{
LINK cur_ptr, next;
cur_ptr = first;
while ( cur_ptr != NULL )
{
next = cur_ptr->next;
if ( strcmp( ipaddr, cur_ptr->ip) == 0 )
strcpy( name, cur_ptr->user );
cur_ptr = next;
}
}
main()
{
LINK first = NULL;
char name[30];
adduser("1.1.1.1", "BATMAN", &first);
getuser( name, "1.1.1.1", first);
cout << name << endl;
return 0;
}