Hi there
I have a problem doing a sorting of my struct.
In my code it scans the file "riget_version3", and stores its data in 'cprnr', 'prio' and 'skade' in my struct, and prints it out.
The data stored and printed is like this:
1111111111 1 F
2222222222 4 A
3333333333 2 C
and so on...
I want to sort this information by the variable 'prio'(short for priority), which has the number 1-4, where 1 is the highest priority.
How can I do this?
HERE IS MY CODE:
Code:
#include <stdio.h>
typedef struct
{
char cprnr[10];
int prio;
char skade;
}Patient;
int main()
{
FILE *f = popen("./riget_version3", "r");
Patient p;
if(!f)
{
fprintf(stderr, "Failed to open riget_version3\n");
return 0;
}
while(fscanf(f, "%[^\t]\t%d\t%c\n", p.cprnr, &p.prio, &p.skade) > 0)
{
/* Process Info */
printf("%s %d %c\n", p.cprnr, p.prio, p.skade);
}
return 0;
}
Thanks a lot
Philip