I am working on "tideman" from pset3 and stuck on sorting the data that i have in "struct" data type. Don't really know if it was supposed to be figured out on our own, but they did not cover the syntax or any function to "swap" the elements in the "struct" data type.
Please help me move forward.
UPDATED I wasn't able to define the problem earlier properly. I have written a sample code to define it, as follows:
#include <stdio.h>
#include <cs50.h>
#include <math.h>
typedef struct
{
string name;
int age;
}
people;
int main(void)
{
int x = get_int("No. of people:");
people person[x];
for (int i = 0; i < x; i++)
{
person[i].name = get_string("%i) Name: ", (i+1));
person[i].age = get_int("%i) Age: ", (i+1));
}
int a = get_int ("a: ");
int b = get_int ("b: ");
}
PLEASE JUST POINT IT OUT IF THE OBJECTIVE OF THIS pset IS TO LET STUDENTS FIGURE THIS OUT*
Now, if it's okay with the "Academic Honesty", in the above code, lets say the user enters data of 4 people (Name and Age). Then in the last two lines of code, the user enters the "serial number" (as in the location of those people in the "person array") of the people who's entry must be "swapped" or "switched" with one another in the "person struct-array"...
Hope I am able to convey the problem now..