Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

C++ problems are fun!

  • 08-10-2002 08:34PM
    #1
    Registered Users, Registered Users 2 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, Registered Users 2 Posts: 935 ✭✭✭Mixie


    .


  • Registered Users, Registered Users 2, Paid Member Posts: 2,032 ✭✭✭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,563 ✭✭✭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