Errors please help

This is a discussion on Errors please help within the C++ Programming forums, part of the General Programming Boards category; I'm trying to finish up some homework, and keep getting the "invalid conversion from `char' to `const char*' " error. ...

  1. #1
    Registered User
    Join Date
    Apr 2007
    Posts
    22

    Errors please help

    I'm trying to finish up some homework, and keep getting the "invalid conversion from `char' to `const char*' " error. I'm trying to insert into a linear linked list, any help would be appericated. Heres the code, I hope its enough of the puzzle.

    Code:
    food_TYPE *data;
    node *type;
    
     head = new node;
     current = new node;
     current = head;
     head->next = NULL;
     
        
            node *temp;
            temp = new node;
            int len;
    
    if(temp)
    {
        //copy into node
        strcpy (current->data->food, foodm);
        strcpy(current->food_TYPE->location, location);
        current->data.rating = rating;
    }

  2. #2
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,794
    Code:
    head = new node;
    current = new node;
    current = head;
    This is a memory leak. You dynamically allocate some new memory to current, then you throw it away when you point current to head. Other than that, it sounds like you problem may be with foodm or location. Show how they are declared along with the declarations for your food_TYPE and node objects.
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  3. #3
    Registered User
    Join Date
    Apr 2007
    Posts
    22
    foodm and location are both in the main, we're implementing ADT's, and cant cin or cout from a class, so I'm trying to pass them from the main to the class.
    The struct food_TYPE is declared in struct.h and struct node is declared in class.h

    Code:
    struct food_TYPE
    {
        char *food; //what type of food is sold
        char *location;  // where food is served
        int rating;      // rating of how good food is 
    //    node *next;        
    };     
    
    struct node
    {
       struct food_TYPE *data;    
       node *next;
    
    };

  4. #4
    Registered User
    Join Date
    Apr 2007
    Posts
    22
    I figured I would post all the code I have for the insert, so you can hopefully figure out where I was headed with this.

    Code:
    //****************************************************************************** 
    ////////////////////////////////////////////////////////////////////////////////
    //class code to insert in sorted order
    int resturant::add_Resturant(char &foodm, char &location, int rating)//, food_TYPE &head, food_TYPE &next)
    {
        resturant Resturant;
           
    
    food_TYPE *data;
    node *type;
    
     head = new node;
     current = head;
     head->next = NULL;
    
    
        
            node *temp;
            temp = new node;
            int len;
    
    if(temp)
    {    
        //copy into node
        strcpy (current->data->food, foodm);
        strcpy(current->data->location, location);
        current->data->rating = rating;   
    }
    else return 0;
    
    if(!head)
    {
        head = temp;
        head -> next = NULL;
    }
    else if (strcmp(head->data, temp->data) >0)
    {
        temp->next = head;
        head = temp;
    }
    else 
    {
        node *current = head ->next;
        node *previous = head;
    }
    while(strcmp(current->data, temp->data)<0)
    {
        previous = current;
        current = current ->next;
    }temp->next = current; 
    
    //delete dynamic memory
    delete data->food;
    delete data->location;
    
    }

  5. #5
    Registered User
    Join Date
    Oct 2006
    Location
    Canada
    Posts
    1,243
    in your function parameters change 'char &foodm' to 'char* foodm'

  6. #6
    Registered User
    Join Date
    Apr 2007
    Posts
    22
    I just wanted to say thanks to all those who responded, I was able to get the program running and turned in, thanks.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. global namespace errors
    By stubaan in forum C++ Programming
    Replies: 9
    Last Post: 04-02-2008, 03:11 PM
  2. Ten Errors
    By AverageSoftware in forum Contests Board
    Replies: 0
    Last Post: 07-20-2007, 10:50 AM
  3. Stupid compiler errors
    By ChrisEacrett in forum C++ Programming
    Replies: 9
    Last Post: 11-30-2003, 04:44 PM
  4. Help me with these errors... :-(
    By major_small in forum C++ Programming
    Replies: 6
    Last Post: 09-07-2003, 08:18 PM
  5. errors in class(urgent)
    By ayesha in forum C++ Programming
    Replies: 2
    Last Post: 11-10-2001, 05:51 PM

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