Thread: Help with error: C2440

  1. #1
    Registered User
    Join Date
    Dec 2003

    Help with error: C2440

    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 *'

    #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'):
    case ('s'):
    case ('S'):
    case ('q'):
    case ('Q'):
    return (0);
    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;


    I attached the code. Any help will be greatly appreciated since I've run out of ideas.

    Last edited by dogman; 12-09-2003 at 04:50 PM.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    Yeah, the main problem is you're compiling C code with a C++ compiler.

    Start by calling your program ml.c

    Then read the FAQ to find out why gets() is very bad
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Dec 2003

    worked like a charm


Popular pages Recent additions subscribe to a feed