Hi all
I need to sort through my array, and put all the patients into a queue. The sorting has to be made solely on 'prio', which takes a number from 1-4, where 1 has highest priority.
Can anyone please give me THE way of doing this, as I have been trying to do so for a couple of days now, with no luck.
Appreciate it all.
Code:
#include <stdio.h>
#include <stdlib.h>
#include "patientStruct.h"
#define MAX 1000
int main()
{
int kontroltal[9] ={4, 3, 2, 7, 6, 5, 4, 3, 2};//kontroltal til modulo11-algoritme
FILE *f = popen("./riget_version3", "r");
Patient p[MAX];
int num = 0;
int num2;
if(!f)
{
fprintf(stderr, "Failed to open riget_version3\n");
return 0;
}
while( num < MAX && fscanf(f, "%[^\t]\t%d\t%c\n", p[num].cprnr, &p[num].prio, &p[num].skade) == 3)
{
/* Process Info */
printf("Cprnr: %s\tPrioritet: %d\t Skadesart: %c\n", p[num].cprnr, p[num].prio, p[num].skade);
/*Kører for-løkke på cpr-array og regner efter med modulo11-algoriten*/
int i;
int sum = 0;
int num10 = (p[num].cprnr[9]-48);
for(i=0;i<9;i++)
{
int n = (p[num].cprnr[i]-48);
num2 = n*kontroltal[i];
sum = sum + num2;
}
if(num10 %2)
strcpy(p[num].sex, "Mand");
else
strcpy(p[num].sex, "Kvinde");
printf("Køn: %s\n", p[num].sex);
int modulo11 = sum%11;
int kontrolcif = 11-modulo11;
if((kontrolcif-num10) == 0)
printf("Dit cpr er gyldigt\n");
else
printf("Dit cpr er ikke gyldigt, du er afvist\n");
printf("_________________________________________________________________________\n");
num++;
}
fclose(f);
// start en sort funktion her evt. qsort
return 0;
}
Here is my patientstruct.h:
Code:
typedef struct
{
char cprnr[9];
int prio;
char skade;
char sex[7];
int fracture;
}Patient;
Appreciate it all.