Hello everyone! I'm trying to solve this particular problem that has been buggin me for a while, because I can't seem to find what i need anywhere on the net. I need to sort some records (6 or 7) read from a dat file using the bubble sort algorithm. I have written some record on file in "w" mode. Now, provided that the following is the code for normally reading my records:
Code:
Code:
FILE * lettura;
struct struttura{
char nome[20];
int anni;
int punti;
int numero;
};
struct struttura stru;
int main()
{
lettura = fopen ("dati.dat", "r");
if (lettura == NULL){
fprintf(stderr, "\nError opening file\n");
exit (1);
}else{
while(fread(&stru, sizeof(struct struttura), 1, lettura)){
printf("dati %s, %d, %d, %d\n", stru.nome, stru.anni, stru.punti, stru.numero);
}
}
fclose(lettura);
}
How can i apply the sorting algorithm here? Can anyone show me the code?