Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Oct 2011
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Simple C functions. Need help

    Hey i can't seem to debug this code, the compiler says syntax error before & token.... It's the first ampersand in the first function, i have underlined it.
    I can't see what's wrong with this code.
    There may be problems elsewhere, but i have yet to get past this first obstacle.

    Code:
    #include <stdio.h>
    
    
    
    void GetData(int &a, int &b)
    {
        printf("Enter first number");
        scanf("%d%*c", &a);
        printf("Enter second number");
        scanf("%d%*c", &b);
        //two values out...
        return;
    
    }
    
    int funcSwap( int &b, int &a)
    {
    
        //two values out...
        return;
    }
    
    void funcPrint(int a, int b)
    {
        printf("First value: ", a);
        printf("Second value: ", b);
        return;
    }
    
    
    int main()
    {
    
        int a,b;
    
        GetData(a,b);
        funcSwap(a,b);
        funcPrint(a,b);
    
    
    
    return 0;
    }
    Last edited by CodeGibbon; 10-04-2011 at 03:43 PM.

  • #2
    Senior Coder
    Join Date
    Aug 2006
    Posts
    1,138
    Thanks
    7
    Thanked 257 Times in 256 Posts
    Here's a quick link to how one passes parameters by reference in C. Take a look at the syntax of the function; that's presumably what you intend...

    Dave

  • Users who have thanked tracknut for this post:

    CodeGibbon (10-04-2011)

  • #3
    New to the CF scene
    Join Date
    Oct 2011
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Thanks Dave, just realised i had to use some of c++ functionality. By saving as cpp file it worked.
    Cheers.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •