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
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

C++ problems are fun!

  • 08-10-2002 7: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 Posts: 2,013 ✭✭✭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