Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

C++ problems are fun!

Options
  • 08-10-2002 8:34pm
    #1
    Registered Users Posts: 2,277 ✭✭✭


    Ahh the begining of another college year and the more new fishes need c++ help :)

    heres me problem.......

    void del_contact(int x)
    {
    contact[x].fname=0;
    contact[x].sname=0;
    contact[x].add1=0;
    contact[x].add2=0;
    contact[x].add3=0;
    contact[x].phone=0;
    contact[x].fax=0;
    contact[x].email=0;
    }

    here be's a function to set all those variables to 0. as youve guessed by my asking here it dosnt work. okay now for the background.

    the variables fname and everything underneath have been defined in a structure contact_list, i then created an array of contact_list called contact. my idea is to pass x to the function to change all data in the contact array element with the same value as x.

    when i compile i get Lvalue errors. Hitting the computer is not an option as im doing this on my computer and not the colleges :)


Comments

  • Registered Users Posts: 935 ✭✭✭Mixie


    .


  • Registered Users Posts: 1,994 ✭✭✭lynchie


    hmm... havent played with structs in a while.

    How have u declared the array of structs?

    If it is declared as a pointer struct contact_list *contacts then the code in the method must be changed to contact[x]->fname=0; etc....

    AFAIK that is what the LValue errors are but I could be wrong.


  • Closed Accounts Posts: 5,564 ✭✭✭Typedef


    
    #include <stdio.h>
    #include <string.h>
    
    typedef struct drink_girls_money_was_resting_in_my_account
    {
     string lalalala;
     int la_la_la;
     float whatever;
    }contact_t;
     
    int some_number=10;
    
    contact_t contact[some_number];
    void del_contact(int x);
    
    int main(int argc,char**argv)
    {
     printf("Who's your daddy baby\n");
     for(a=0;a<some_number;a++)
     {
       del_contact(a);
     };
     printf("Life is like a box of chocolates\n");
    return 0;
    };
    
    void del_contact(int x)
    {
    contact[x].fname=0;
    contact[x].sname=0;
    contact[x].add1=0;
    contact[x].add2=0;
    contact[x].add3=0;
    contact[x].phone=0;
    contact[x].fax=0;
    contact[x].email=0;
    return;
    }
    
    

    hmm hope this helps.


Advertisement