In an example program my professor gave me that reads data from a file about rooms. For example the data file reads:
Bill Mueller
129450.93 4
2:300.5:Living Room
1:107.0:Bedroom 1
2:158.3:Master Bedroom
3:98.3:Kitchen
The last 4 lines are the lines that have to do with the rooms. The first number is the number of windows, the second (after the colon) is the area, and the last is the name of the room. I have to read data in, store the room info in a dynamically allocated array of structs, sort the array by area (from smallest area to largest), and then display the results.
In main, he just has variable declarations and calls these 3 functions:
Code:
read_file(&rooms, &price, owner, &num, argc, argv);
sort(rooms, num);
show_results(rooms, price, owner, num);
My question is regarding the sort() function. He uses an insertion sort algorithm, but I thought that you will need to pass the address of the rooms struct to sort()? Because you are changing the values of rooms[1], rooms[2], etc., so in order for show_results() to show the sorted results, I would need to pass the address of rooms (&rooms) to sort()? But this works, I just need a little explanation why you don't have to use pointers here. thanks