You cannot use typedef to define a function.
Typedef your structure first how
typedef struct { int dice1; int dice2; } diceData;
Then declare your function as
diceData RollDice() { diceData diceRoll; diceRoll.dice1 = 0; diceRoll.dice2 = 0; return diceRoll; }
Declares RollDice as a function that returns a diceData structure.
An alternative way to handle an attempt to return two values would be to use parameters.
In this case, your function will return a boolean value (to indicate success or failure) and take two pointers to integers as parameters. Inside the function, you fill in the contents of pointers, for example:
bool_t rollDice(int *pDice1, int *pDice2) { if (pDice1 && pDice2) { *pDice1 = 0; *pDice2 = 0; return TRUE; } else { return FALSE; } } int main(int argc, char **argv) { int a, b; rollDice(&a, &b); return 0; }
Vicky
source share