...

View Full Version : Simple C functions. Need help



CodeGibbon
10-04-2011, 04:39 PM
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.



#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;
}

tracknut
10-04-2011, 04:47 PM
Here's a quick link (http://stackoverflow.com/questions/2229498/passing-by-reference-in-c) 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

CodeGibbon
10-04-2011, 04:57 PM
Thanks Dave, just realised i had to use some of c++ functionality. By saving as cpp file it worked.
Cheers.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum