How do I send pointers into this function?

This is a discussion on How do I send pointers into this function? within the C Programming forums, part of the General Programming Boards category; I have the following function declaration: Code: extern int function(int *grade, double *average); How do I send numbers into this ...

  1. #1
    Registered User
    Join Date
    Sep 2008
    Posts
    58

    How do I send pointers into this function?

    I have the following function declaration:
    Code:
    extern int function(int *grade, double *average);
    How do I send numbers into this function?


    I tried:
    Code:
    int *grade;
    double *average;
    function(*grade, *average);
    I also tried it without the *. Both give me errors..

    ???

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,794
    function(grade, average) should be correct, except that grade and average are not initialised. What exactly does this function do? Perhaps grade and average should not be pointers, and instead you want to call function(&grade, &average).
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User C_ntua's Avatar
    Join Date
    Jun 2008
    Posts
    1,853
    Code:
    int grade, average;
    function(&grade, &average);
    the & means the address

    EDIT: Just show lasersights post. You probably want to do what I posted. It is not wrong what you are doing, but I guess the function expects to pass a pointer that actually points at an allocated space.
    Try what I posted and try this also:
    Code:
    int *grade = malloc(sizeof(int));
    int *average = malloc(sizeof(int));
    function(grade, average);
    Last edited by C_ntua; 10-15-2008 at 11:40 AM.

  4. #4
    Registered User
    Join Date
    Sep 2008
    Posts
    58
    Quote Originally Posted by C_ntua View Post
    Code:
    int grade, average;
    function(&grade, &average);
    the & means the address

    EDIT: Just show lasersights post. You probably want to do what I posted. It is not wrong what you are doing, but I guess the function expects to pass a pointer that actually points at an allocated space.
    Try what I posted and try this also:
    Code:
    int *grade = malloc(sizeof(int));
    int *average = malloc(sizeof(int));
    function(grade, average);
    PERFECT.. thanks

  5. #5
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    scarlet00014, what sort of book are you using to learn C?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. sorting number
    By Leslie in forum C Programming
    Replies: 8
    Last Post: 05-20-2009, 04:23 AM
  2. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  3. c++ linking problem for x11
    By kron in forum Linux Programming
    Replies: 1
    Last Post: 11-19-2004, 09:18 AM
  4. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 09:33 AM
  5. Contest Results - May 27, 2002
    By ygfperson in forum A Brief History of Cprogramming.com
    Replies: 18
    Last Post: 06-18-2002, 01:27 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21