passing arguments through functions

This is a discussion on passing arguments through functions within the C Programming forums, part of the General Programming Boards category; just look at this and tell me why it won't output anything, it will compile, but won't output anything, I ...

  1. #1
    cwd
    cwd is offline
    Registered User
    Join Date
    Sep 2001
    Posts
    9

    passing arguments through functions

    just look at this and tell me why it won't output anything, it will compile, but won't output anything, I need to know soon, real soon

    #include <stdio.h>
    #define value 30

    int test(int x);

    int main()
    {
    int x=1;
    while(x<=value)
    {
    int test(int x);
    x++;
    }
    return 0;
    }

    int test(int x)
    {
    if((x<=10)&&(x%2==0))
    {
    printf("%d : EVEN",x)
    }
    else if(x<=10)
    {
    printf("%d : ODD",x)
    }
    }

  2. #2
    Unregistered
    Guest
    When you call the function all you want to do is give it the name of the variable you want to pass to it, not the data type as well.

    int test(x);

    The way you had it you were actually declaring a new int called x when one already existed. This new variable has no value so the program will either not work or spit out garbage assuming you don't get an error.

  3. #3
    Registered User sballew's Avatar
    Join Date
    Sep 2001
    Posts
    157
    in your code here

    Code:
    
    int main() 
    { 
    int x=1; 
    while(x<=value) 
    { 
    int test(int x);    /*  change to test(any variable declared )  */
    x++; 
    } 
    return 0; 
    }
    you are not calling the function 'test' correctly

    you just need to code it as:

    name of function(any local variable called before call of function)
    test(y); /* declare y as int variable and it'll work */
    Sue B.

    dazed and confused


Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Functions Taking Dif. Numbers of Arguments at Dif. Times?
    By bengreenwood in forum C++ Programming
    Replies: 6
    Last Post: 03-23-2009, 04:12 PM
  2. Problem Passing Values between functions
    By jamez05 in forum C++ Programming
    Replies: 2
    Last Post: 05-02-2007, 01:21 PM
  3. Passing functions between files
    By Duskan in forum C Programming
    Replies: 9
    Last Post: 04-17-2007, 07:44 AM
  4. Passing pointers between functions
    By heygirls_uk in forum C Programming
    Replies: 5
    Last Post: 01-09-2004, 05:58 PM
  5. Replies: 1
    Last Post: 01-20-2002, 10:50 AM

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