Thread: Passing arguments.

  1. #1
    Novice.
    Join Date
    Oct 2005
    Posts
    88

    Thumbs up Passing arguments.

    When I want to pass multiple arguments to a function, and do the same thing to all of these arguments, is there an easy way to do this?

    Code:
    void vul(ruiten[4], harten[4], klaver[4], schoppen[4])
    {
    	int a;
    	for (a = 0; a < 4; a++)
    	{
    		array[a] = a;
    	}
    return;
    The idea is that the function vul fills, every array with numbers from 0-3.

    It won't work this way, but is there a way? Or am I being completely confused right now?

    Thank You.

  2. #2
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    You could just write a function to perform operation X on the array you pass as argument and call that function n times.
    (So if you wanted a function to do Y with n arrays, write a function that does this operation on an array passed as argument and call this function for every array.)
    Also note that all arguments must have types.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #3
    Novice.
    Join Date
    Oct 2005
    Posts
    88
    I don't really understand the part: "write a function that does this operation on an array passed as argument"

    How can I make a calculation with an array, that is array independant. I mean that it doesn't matter which array you give it.

  4. #4
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    You can't make it independent. Just see it as breaking the original function into parts. Specialized parts.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Passing arguments
    By jcafaro10 in forum C++ Programming
    Replies: 2
    Last Post: 01-25-2009, 01:14 PM
  2. Passing arguments between functions
    By Wiretron in forum C Programming
    Replies: 4
    Last Post: 05-17-2006, 04:59 PM
  3. Passing arguments to function...
    By alvifarooq in forum C++ Programming
    Replies: 8
    Last Post: 09-24-2004, 12:50 PM
  4. passing arguments
    By Baard in forum C++ Programming
    Replies: 3
    Last Post: 12-23-2003, 08:10 AM
  5. Question about Templates and passing arguments
    By supaben34 in forum C++ Programming
    Replies: 2
    Last Post: 10-13-2002, 01:32 AM