My problem is sort some numbers taken from a txt file. When I compile the file the program stop working.
#include <stdio.h>
#include <stdlib.h>
struct student_grades{
int number;
char name[10];
char surname[10];
int grade;
};
typedef struct student_grades stgrade;
void bubble_sort(int list[], int n){ //Line 16
long c, d, t;
for (c = 0 ; c < ( n - 1 ); c++)
{
for (d = 0 ; d < n - c - 1; d++)
{
if (list[d] > list[d+1])
{
/* Swapping */
t = list[d];
list[d] = list[d+1];
list[d+1] = t;
}
}
}
}
int main()
{
int i=0;
FILE *stu; // file tipinde değişken tutacak
FILE *stub;
stu= fopen("student.txt","r");
stub= fopen("stu_order.txt","a");
stgrade stg[12];
if(stu!=NULL){
while(!feof(stu))
{
fscanf(stu,"%d",&stg[i].number);
fscanf(stu,"%s",stg[i].name);
fscanf(stu,"%s",stg[i].surname);
fscanf(stu,"%d",&stg[i].grade);
//fprintf(stub,"%d %s %s %d\n",stg[i].number,stg[i].name,stg[i].surname,stg[i].grade);
++i;
}
bubble_sort(stg->number,12); //Line 59
fprintf(stub,"%d %s %s %d\n",stg[1].number,stg[1].name,stg[1].surname,stg[1].grade); //control that is bubble success?
}
else
printf("File Not Found");
fclose(stu);
fclose(stub);
return 0;
at first i write the line 59
bubble_sort(stg.number,12);
like this . But it gets error and not compile. I change it with
bubble_sort(stg->number,12);
this it compiled but stop working and get warning
Formatted Output :
In function 'main':
59 3 [Warning] passing argument 1 of 'bubble_sort' makes pointer from integer without a cast [enabled by default]
16 6 [Note] expected 'int *' but argument is of type 'int'
the student.txt
80701056 Sabri Demirel 45
52801022 Burak Erkin 68
13801045 Umut Korkmaz 88
74801334 Semih Potuk 58
15678544 Enes Sezer 76
42125884 Ahmet Can 84
12355488 Emre Ozdemir 47
18744125 Ugur Yildiz 64
62184111 Mustafa Ozturk 80
18412548 Ugur Akkafa 72
94541771 Hakan Aktas 92
36945245 Fatih Yagci 98