Question

float generateCoor()
{
    srand(time(NULL));

    coordinate cd; //structure variable
    cd.rx = genRand();
    printf("X-coordinate: %.2f\n",rx);

    cd.ry = genRand();
    printf("Y-coordinate: %.2f\n",ry);
}

Now since one function cannot return two variables simultaneously, than how can I return the co-ordinates back to the main function?

Was it helpful?

Solution

You can use either of following :-

coordinate generateCoor() { ... return cd;} 

int main(){
coordinate c = generateCoor();
}

OR

void generateCoor(coordinate *cd) { ... }  

//Give it a proper name something like constructCoor 

int main(){
coordinate c;

generateCoor(&c);
}

OTHER TIPS

You can create structure, and return pointer to that structure.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top