Well, my apologies for making the homework assumption. Is this what you're looking for?
Code:
#include <stdio.h>
#include <stdlib.h>
typedef struct
{
int id;
} Student;
void sort(Student *list, int num)
{
Student *outer, *inner;
Student temp;
for(outer = list;outer-list < num;++outer)
for(inner = outer+1;inner-list < num;++inner)
if(outer->id > inner->id)
{
temp = *outer;
*outer = *inner;
*inner = temp;
}
}
int main(void)
{
Student *list = NULL, *ptr;
int n_students = 0;
char buf[256];
puts("Enter IDs one per line. Blank line to end.");
for(;;)
{
printf("ID %d: ", n_students+1);
fflush(stdout);
fgets(buf, sizeof(buf), stdin);
if(*buf == '\n')
break;
if(!(ptr = realloc(list, sizeof(Student)*(n_students+1))))
{
puts("Memory allocation error. Processing existing IDs...");
break;
}
list = ptr;
list[n_students++].id = atoi(buf);
}
sort(list, n_students);
for(ptr = list;ptr-list < n_students;++ptr)
printf("%08d\n", ptr->id);
free(list);
return 0;
}
itsme@dreams:~/C$ ./idsort
Enter IDs one per line. Blank line to end.
ID 1: 27270
ID 2: 28578
ID 3: 27896
ID 4:
00027270
00027896
00028578
itsme@dreams:~/C$