Thread: C++ code question

  1. #1
    Registered User
    Join Date
    Oct 2006
    Posts
    12

    C++ code question

    I need to remove an existing structure from a linked list of structures and the argument passed to remove() should be the address of the structure preceding the record to be removed....is this a good start?

    Code:
    #include <iostream>
    #include <string>
    using namespace std;
    
    struct Info
    {
     string name;
     string teleno;
     };
     
     void remove(Info*);
      
    int main()
    {
     Info * val;
     int i;
     
     cout<< "Enter a name:  ";
      cin>> val -> name;
     cout<< "Enter a telephone number:  ";
      cin>> val -> teleno;
    
    return 0;  
    }

  2. #2
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    It is ok as a start. You need to have your val point actually point to something, although I don't know why it needs to be a pointer.

    You also don't have a linked list. Were you supposed to make the structure a linked list node?

    You'll also probably have to walk through the list to find the element to delete.

    It's hard to say whether that really is a good start because I don't know the rest of the context.

  3. #3
    Registered User
    Join Date
    Oct 2006
    Posts
    12
    does this look a bit better?

    Code:
    struct Info
    {
       string name;
       string teleno;
       Info * next;
    };
     
     void remove(Info*);
     
    int main()
    {
    
    Info num;
    num = remove();
    cout << "The name is:  " << num.name
    cout << "The telephone number is:  " << num.teleno << endl;
    
    return 0; 
    }

  4. #4
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    Info looks more like a list now, but I'm not sure what you are trying to do inside your main function.

    Do you have a written out (in words) description of everything you plan on doing?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Hi all i have a question about a code
    By iweapons in forum C++ Programming
    Replies: 5
    Last Post: 05-23-2007, 11:05 AM
  2. I need help to compile this code...
    By wise_ron in forum C Programming
    Replies: 17
    Last Post: 05-07-2006, 12:22 PM
  3. My First If Code, Question? :P
    By dimirpaw in forum C++ Programming
    Replies: 3
    Last Post: 11-29-2005, 08:49 PM
  4. End of Code Loop Question
    By JuanSverige in forum C++ Programming
    Replies: 1
    Last Post: 04-08-2003, 10:35 AM
  5. question about my code
    By killerasp in forum C++ Programming
    Replies: 7
    Last Post: 02-18-2002, 08:05 PM