0

Help me!!! (Solved)

Question:✓Write a c program to get 5 subject marks of n number of students and display the total marks rankwise. Problem:✓How to create a dynamic array of structs of students and work with it!? If you don't know the answer, please upvote it so that others can find it and answer

4th May 2021, 9:51 AM
Rishi
Rishi - avatar
9 Antworten
+ 4
If you use C++, you can use container like std::vector: std::vector<Students> arr; or make pointer: Students* arr = new Students[size]; There are more containers, check them here if you want: https://www.cplusplus.com/reference/stl/ If you use C, make dynamic array with pointer: Students* arr = (Students*)malloc(sizeof(Students)*size); Btw it would be nice to see your attempt, or full content of the task. In addition, you have completed only half of C course, so you did not face memory management problem yet. Continue learning so you'll solve your problem by yourself
4th May 2021, 9:54 AM
Michal Doruch
+ 2
Calvin Thomas did you do it yourself!? I understand only 60 percent of it. And it says "execution timed out" when I run it
6th May 2021, 2:46 PM
Rishi
Rishi - avatar
+ 1
Rishi Yes, I had done it myself, and the code is pretty straightforward in my opinion (I guess that the only part which appears vague at first sight is the bubble-sort loop). As said previously, the code is pretty slow (due to all the reallocs and de-referencing) and thus, requires a fast and a stable internet connection to show the output. Try reducing the number of names to two, if it still bothers you.
6th May 2021, 3:52 PM
Calvin Thomas
Calvin Thomas - avatar
+ 1
Rishi ,it says execution timed out, cuz you have to type "Y" to break out of that infinite loop: for (int i=0;1;i++)
6th May 2021, 4:07 PM
Michal Doruch
0
If you are opting for C then (as already pointed by Michał Doruch ) you can use malloc() to allocate memory dynamically. You have to keep track of size and just in case it overflows, you can create a new array dynamically of larger size and copy all of it's contents from previous array to the new one and delete the old one. In C++, all this has already been implemented in standard library as vectors for you to use easily.
4th May 2021, 1:01 PM
Arsenic
Arsenic - avatar
0
I tried it using these methods and solved it. Plus I already learnt a lotta C++, but now I have to learn C because of my college syllabus which makes no sense. Anyway, thank you 🙂
4th May 2021, 3:54 PM
Rishi
Rishi - avatar
0
Rishi Here is a C code that does the mentioned job (using dynamic arrays): https://code.sololearn.com/csxHsJzFsO8z/?ref=app
4th May 2021, 8:10 PM
Calvin Thomas
Calvin Thomas - avatar
0
It says "oops something went wrong when I try to enter this link"
6th May 2021, 5:24 AM
Rishi
Rishi - avatar
6th May 2021, 6:19 AM
Calvin Thomas
Calvin Thomas - avatar