Well you're current code is swapping only the values inside an 1 array only?
Maybe a good sorting algorithm will help you clear some things out
note: you can find more better examples if you search on google
yh i made the correction ive decided that the best way to sort the three arrays is to make bubble sort module and make a file that stores the data and and let the sort module sort it something like this:
#include
#include
int bubble (int* ,int);
void filewrite();
void avgmarks();
void fileprint();
void filesort();
void rollin();
/***********************SORTING FUNCTION*********************/
int bubble(int x[],int n)
{
int hold,j,pass,switched = 1;
for (pass=0;pass < n-1 && switched==1;pass++)
{
switched = 0;
for (j=0;jx[j+1])
{
switched = 1;
hold = x[j];
x[j] = x[j+1];
x[j+1] = hold;
}
}
}
return 0;
}
/***********************FILE WRITING FUNCTION************************/
void filewrite()
{
int roll,ch,mark;
char nam[50];
FILE *fp;
fp = fopen("student.txt","a");
printf("ENTER ROLL NUMBER, NAME, MARKS\n");
ch= 1;
while(ch)
{
scanf("%d%s%d",&roll,&nam,&mark,"a");
fprintf(fp,"%d %s %d\n",roll,nam,mark);
printf("\n\n press 1 to continue, 0 to stop");
scanf("%d",&ch);
}
fclose(fp);
}
/************************OUTPUTTING DATA ON SCREEN*********************/
void fileprint()
{
int marks[100], rollno[100],i;
char name[100] [50];
FILE *fp;
fp = fopen("student.txt","r");
i=0;
printf("ROLLNO\tNAME\tMARK\n");
while (!feof(fp))
{
fscanf(fp,"%d %s %d\n", &rollno[i],&name[i],&marks[i]);
printf("%d\t%s\t%d\n",rollno[i],name[i],marks[i]);
i++;
}
fclose(fp);
printf("\n\n\nPRESS ANY KEY");
getch();
}
/************************SORTING FILE**************************/
void filesort()
{
int marks[100],rollno[100],x[100],n,i,j;
char name[100][50];
FILE *fp, *fm;
fp=fopen ("student.txt","r");
fm=fopen("marks.txt","w");
i = 0;
while (!feof(fp))
{
fscanf (fp,"%d %s %d\n",&rollno[i],&name[i],&marks[i]);
x[i] = marks[i];
i=i+1;
}
n=i;
bubble (x,n);
for (i=0;i