calling/passing functions

This is a discussion on calling/passing functions within the C Programming forums, part of the General Programming Boards category; I'm trying to call a fuction: Code: int DetermineEvent(parameters *p, char *paramfile, double X, double u, double dt, int *left, ...

  1. #1
    Registered User
    Join Date
    Aug 2006
    Posts
    64

    calling/passing functions

    I'm trying to call a fuction:
    Code:
    int DetermineEvent(parameters *p, char *paramfile, double X, double u, double dt, int *left, int *right, int *add)
    from the main file, what would it look like:
    Code:
    c = DetermineEvent(*p, *paramfile, X, u, dt, *left, *right, *add)
    I don't think that's right...I know to remove declarations like double and int, but I suspect I should remove parameters, and char and the likes as well?

  2. #2
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,211
    Quite a few ways it could look. Consider a function prototype like this:

    Code:
    int somefunction(int *p);
    Consider this as a way of calling it:

    Code:
    int x = 5;
    
    ....
    
    somefunction(&x);
    Now consider this:

    Code:
    int x[100];
    
    ...
    
    somefunction(x);
    What is somefunction() really expecting? We don't know. Same for your function. RTM, or in this case, the documentation with regard to whatever library you're using that has that function.

  3. #3
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,175
    It depends on how your variables are declared.

    EDIT: Mac beat me.
    If you understand what you're doing, you're not learning anything.

  4. #4
    Registered User
    Join Date
    Aug 2006
    Posts
    64

    Question

    Quote Originally Posted by vutek0328 View Post
    I'm trying to call a fuction:
    Code:
    int DetermineEvent(parameters *p, char *paramfile, double X, double u, double dt, int *left, int *right, int *add)
    from the main file, what would it look like:
    Code:
    c = DetermineEvent(*p, *paramfile, X, u, dt, *left, *right, *add)
    So here I'm trying to pass multiple stuff through to the function, such as a set of parameters stored in the pointer p, the values of the parameters stored in the pointer paramfile, then some variables that I will be use to do computation in the function.

    So how would I express specifically in my main function? When I do
    Code:
    c = DetermineEvent(parameters p, paramfile, X, u, dt, hopleft, hopright, add)
    
    error: parse error before "parameters"

  5. #5
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,211
    Reread our posts. We don't know how you declared those variables, so we don't even know if it's right. If you just want it to compile and possibly crash, then take out "parameters" in the first argument since it's just a data type, not a variable name.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Void Functions Help
    By bethanne41 in forum C++ Programming
    Replies: 1
    Last Post: 05-09-2005, 06:30 PM
  2. Functions and Classes - What did I do wrong?
    By redmage in forum C++ Programming
    Replies: 5
    Last Post: 04-11-2005, 12:50 PM
  3. calling functions within functions
    By edd1986 in forum C Programming
    Replies: 3
    Last Post: 03-29-2005, 03:35 AM
  4. Factory Functions HOWTO
    By GuardianDevil in forum Windows Programming
    Replies: 1
    Last Post: 05-01-2004, 02:41 PM
  5. Shell functions on Win XP
    By geek@02 in forum Windows Programming
    Replies: 6
    Last Post: 04-19-2004, 06:39 AM

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