954,492 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Module that sorts 4 arrays

Need help making a module that sorts 4 arrays this how it started out


void dataSort (float sLengthArray[],float rSlopeArray[],float speedArray[], float size)
{
void swap (int *x,int *y);
int pass,j;

for (pass=0;pass < size-1; pass++)
{
for (a = 0;j< size-1; j++)
{
if (slengthArray[j] > slengthArray[j + 1])
{
swap(&slengthArray[j],&slengthArray[j+1]);
}
}

}
}

void swap ( int *x,int *y)
{
int hold=*x;
*x = *y;
*y = hold;
}

jaymayne
Newbie Poster
13 posts since Jan 2012
Reputation Points: 10
Solved Threads: 0
 

Could you explain your problem and your code more clearly...
What exactly is the output you want to achieve?
Can you give us an idea of what you want to do next or are you asking for suggestions for what to do next?

zeroliken
Veteran Poster
1,106 posts since Nov 2011
Reputation Points: 201
Solved Threads: 162
 
for (a = 0;j< size-1; j++)

What is 'a' ? I think it should be j ?void swap (int *x,int *y);
You have written a function prototype inside another function. That is wrongvoid dataSort (float sLengthArray[],float rSlopeArray[],float speedArray[], float size)
I find only three arrays here,not 4Could you explain your problem and your code more clearly...
What exactly is the output you want to achieve?
Can you give us an idea of what you want to do next or are you asking for suggestions for what to do next?
As zeroliken said, now let us know what exactly you want..

DJSAN10
Posting Whiz in Training
249 posts since Dec 2010
Reputation Points: 38
Solved Threads: 26
 
Could you explain your problem and your code more clearly... What exactly is the output you want to achieve? Can you give us an idea of what you want to do next or are you asking for suggestions for what to do next?

I just would like to know if i am on the right track in sorting three arrays at once or how to do that becuz i only know how to sort one array.

jaymayne
Newbie Poster
13 posts since Jan 2012
Reputation Points: 10
Solved Threads: 0
 

What is 'a' ? I think it should be j ?

You have written a function prototype inside another function. That is wrong

I find only three arrays here,not 4

As zeroliken said, now let us know what exactly you want..

Actually you can declare a prototype within a module if itz the only module calling that function and yh itz three arrays my bad i just want to know if im on the right track or if im not or do i sort three arrays in one sort module

jaymayne
Newbie Poster
13 posts since Jan 2012
Reputation Points: 10
Solved Threads: 0
 
for (a = 0;j< size-1; j++)


Did you already fix this? like DJSAN10 suggested

zeroliken
Veteran Poster
1,106 posts since Nov 2011
Reputation Points: 201
Solved Threads: 162
 

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

zeroliken
Veteran Poster
1,106 posts since Nov 2011
Reputation Points: 201
Solved Threads: 162
 
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

jaymayne
Newbie Poster
13 posts since Jan 2012
Reputation Points: 10
Solved Threads: 0
 

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 does that mean you've finished your program and have no more questions... if so then you mark this thread as solved oh and next time don't forget to wrap your codes in code tags to make it more presentable and readable in your posts :)

zeroliken
Veteran Poster
1,106 posts since Nov 2011
Reputation Points: 201
Solved Threads: 162
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: