# Thread: Sorting exam score in increasing order

1. ## Sorting exam score in increasing order

Hello, I'm a first year university student that has just started learning C language. Right now, I'm trying to learn the section on "Sorting" and found this program online, which generates ramdom student names and scores, and sort the scores out in increasing order. As indicated on the attached program (sort.c), I want to make the labled section as a separate function outside of the main function i.e. sort_mod.c <---not working

Could someone teach me how would I go about doing this? Thanx in advance!

Best regards, superman

2. That code doesn't free the malloc()ed memory. You should free it.

First of all, you should put in a prototype for your function.

Code:
`void mysort(int group[].point,SIZE)`
SIZE has to have a type, like int SIZE. Unless you're referring to the #define SIZE. In that case you don't need to pass it as an argument at all.
Code:
`void mysort(struct student group[])`
And when you call your function (from main()), you would do it like this:
Code:
`mysort(group);`
Read up on structs and functions.

3. Thank you very much your help! I appreciate it !

4. I modified the program and compiled with GCC, and now it gives me the following errors!

sort_mod.c:14: error: syntax error before '.' token
sort_mod.c: In function `mysort':
sort_mod.c:27: error: incompatible types in assignment
sort_mod.c:27: error: incompatible types in assignment

Could someone tell me what's wrong with the program?? Thanx in advance!

Best regards, superman

5. The prototype for mysort is still wrong, make it more like:
void mysort(struct student group[]);

The w variable within mysort should be the same type that you wish to swap around:
struct student w;
(not int w;)

6. Thanx!

Regards, superman