I am having a lot of difficulty's with this assignment for class, ive referenced my textbook aswell as previous programs and cant figure out how to complete it
here is the assignment:
Complete the program to add a prototype for and a definition of the swap_points function. This function should take pointers to two instances of struct Point, and modify them so that the first one contains the second one's original data, and the second one contains the first one's original data.
here is the code provided to me, the program/resource automatically executes it without asking for input from the user
Code:
#include <stdio.h>
// Do not change the definition of this data type
struct Point {
double x, y;
};
// TODO: add a prototype for the swap_points function
(The code i have completed and posted below)
// IMPORTANT: do not modify the main function in any way
int main(void) {
struct Point p, q;
scanf("%lf %lf %lf %lf", &p.x, &p.y, &q.x, &q.y);
swap_points(&p, &q);
printf("Result: p.x=%lf, p.y=%lf, q.x=%lf, q.y=%lf\n", p.x, p.y, q.x, q.y);
return 0;
}
// TODO: add a definition for the swap_points function
Here is the code with what i could figure out:
Code:
// TODO: add a prototype for the swap_points function
struct Point swap_points(){
struct Point hold;
struct Point p;
struct Point q;
hold.x = p.x;
p.x = p.y;
p.y = hold.x;
hold.y = q.x;
q.x = q.y;
q.y = hold.y;
return hold;
}
The program compiles, but returns whatever was inputted, none of the computations are being reached by the call to the function or something of the sorts, any help or explanation of the program/ assignment would be appreciated