Help with error: C2440

This is a discussion on Help with error: C2440 within the C Programming forums, part of the General Programming Boards category; I am writing a mailing list program that is not complete yet. I am currently working on the add to ...

  1. #1
    Registered User
    Join Date
    Dec 2003
    Posts
    2

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

    [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
    Last edited by dogman; 12-09-2003 at 03:50 PM.

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,687
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    Dec 2003
    Posts
    2

    worked like a charm

    thanks!

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21