Thread: Please help with a few things

  1. #1
    Registered User
    Join Date
    Sep 2005
    Posts
    92

    Please help with a few things

    Thanks cwr for your advice it really did help clear up a few things.

    But I just don'nt know how to pass the parameter to the gunction test. I want to pass the sturcture as a function parameter and uses it's variables in the new function. I was hoping If somebody can show me how to do it.

    Code:
    typedef struct{
    	int number;
    	int place;
    	int postcode;
    } information_t;
    
    int test(information_t *in);
    
    int main()
    {
    	information_t information;
    	information *in;
    	
    printf(" Please enter the number: ");
    scanf(" %d",&information.number);
    
    printf(" Please enter the place: ");
    scanf(" %d",&information.place);
    
    printf(" please enter the postcode: ");
    scanf(" %d",&information.postcode);
    
    test(&information_t  *in);
    
    return 0;
    }
    
    int test(information_t  *in)
    {
    	int position;
    	position= scanf(" %d%d%d", &in->number, &in->place, &in->postcode);
    	
    return(position);
    }

  2. #2
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    Code:
    test(&information);
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  3. #3
    Registered User cbastard's Avatar
    Join Date
    Jul 2005
    Location
    India
    Posts
    167
    Quote Originally Posted by HAssan
    information_t information;
    information *in;

    test(&information_t *in);

    [/code]
    check this error.

  4. #4
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    So to pass a pointer to a function that expects a pointer, don't use an ampersand:
    Code:
    void test(int *i);
    
    int *p;
    test(p);  /* no ampersand */
    But to pass a regular variable to a function that expects a pointer, use an ampersand:
    Code:
    void test(int *i);
    
    int integer;
    test(&integer);
    And finally, to pass a pointer to a function that expects a regular variable, dereference the pointer:
    Code:
    void test(int i);
    
    int *p;
    test(*p);
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Suggestions for things to study
    By Mastadex in forum Windows Programming
    Replies: 5
    Last Post: 08-18-2008, 09:23 AM
  2. Plants that eat things
    By StinkyRyan in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 07-05-2004, 03:41 PM
  3. How are things looking
    By cyberCLoWn in forum C++ Programming
    Replies: 8
    Last Post: 01-15-2004, 02:53 PM
  4. Selecting things on the canvas
    By Barjor in forum Windows Programming
    Replies: 0
    Last Post: 08-30-2001, 02:10 PM
  5. Help with these three things...
    By face_master in forum C++ Programming
    Replies: 2
    Last Post: 08-26-2001, 07:05 AM