Sorting structures lexicographically
Is there any way to improve the code when the structure entries are heavy.


1st idea is to use a different sort method.  This code runs in O(n*n) time with the for(i=0; i&lt;n-1; i++) for(j=i+1; j&lt;n; j++) loops.

Various sorts operate in O(n*lo2(n)) time and are not too difficult to code.

2nd idea: Make an array of pointers to the list and sort that.  Then only pointers need to be moved during the heavy part of the algorithm.  When done, the final list can then be arranged per the pointer list.

3rd.  Use a hash table for even faster sorting.  Of course, this is more code and complexity.



General coding observations


fflush(stdin); is non-portable.  Code should be able to be written without it.  Better to use fgets() and then scan the string.
printf("Enter city\n"); scanf("%s",c[i].city); is problematic for 1) it does not limit input to 99 characters as needed per the buffer size.  Many cities have a space in their name "New York" and "%s" does not save spaces.  Use fgets() and lop off the tailing '\n' as needed.  name[] too.
Best to validate input:  check return value from *scanf() functions.
The check it too late. Do it before declaring College[]

// struct College c[n];
if(n&lt;=0) 
  ...
struct College c[n];





A point on improved sorting methods.

By sorting on name[] only, code could have multiple entries with the same name like "John Adams".  With OP's slow O(n*n) method, a benefit to it is that it is a stable sort.  OP's sorting would not change the sequence concerning ties.

Now consider the standard function qsort()  with a simple compare function that only reference name[], then the order of entries on ties is not guaranteed.  


  "If two elements compare as equal, their order in the resulting sorted array is unspecified."  C11 §7.22.5.2


Many fast methods do not guarantee stability.

A classic solution is to include a unique index number with each College[].  Then when there is a tie on the name[], the index could be the tie breaker, ensuring a stable sort.  With the reference table idea far above, possible the "index" could be the College[] address (a pointer) in a clever usage, thus incurring no additional memory cost.