I am writing a mailing list program that is not complete yet. I am currently working on the add to list function but I am getting c:\Documents and Settings\JH\Desktop\ML\ML.cpp(48): error C2440: '=' : cannot convert from 'void *' to 'MailingList *'
[code]
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct MailingList {
char name[40];
char address[40];
char city[20];
char state[3];
struct MailingList *next;
};
void add_to_list (void); /* Add a name to address book */
void search (void); /* Delete a name from address book */
struct MailingList *hol= NULL; /* Head of linked list of addresses -
global variable*/
int main()
{
char input[2]; /* Input from the user */
while (1) {
printf ("Please choose one of the following: (A)dd/(S)earch/(Q)uit\n");
gets (input);
switch (input[0]) {
case ('a'):
case ('A'):
add_to_list();
break;
case ('s'):
case ('S'):
break;
case ('q'):
case ('Q'):
return (0);
default:
printf ("Unknown command\n");
}
}
return 0;
}
void add_to_list ()
/* Add a new name to our address book */
{
struct MailingList * add_name;
add_name = malloc(sizeof(struct MailingList));
if (add_name == NULL) {
printf ("Out of memory!\n");
exit (-1);
}
/* Get input for the new item */
printf ("Name: ");
gets (add_name->name);
printf ("Address: ");
gets (add_name->address);
printf ("City: ");
gets (add_name->city);
printf ("State: ");
gets (add_name->state);
/* Chain the new item into the list */
add_name->next= hol;
hol= add_name;
}
[\code]
I attached the code. Any help will be greatly appreciated since I've run out of ideas.
Thanks