fin troubles

Please support our C advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Nov 2004
Posts: 2
Reputation: toadie2004 is an unknown quantity at this point 
Solved Threads: 0
toadie2004 toadie2004 is offline Offline
Newbie Poster

fin troubles

 
0
  #1
Nov 15th, 2004
This is my project:
Read the data one line at a time and store them in two different arrays.

Pass the first array to a function that sorts the array in ascending
order using selection sort.

Pass the second array to a function that sorts the array in descending
order using selection sort.

(Use your functions from the previous assignment to sort.)


Print each array before and after sorting.

***my main problem is that im having much trouble reading the numbers from the .dat file and storing them in an array, any help you could give me would be great...thanks

void ascendingsort(int list[], int length)
{
int index, smallestindex, minindex, temp;
for (index = 0; index < length - 1; index++)
{
smallestindex = index;
for (minindex = index + 1;minindex < length; minindex++)
if (list[minindex] < list[smallindex])
smallestindex = minindex;

temp = list[smallestindex];
list[smallestindex] = list[index];
list[index] = temp;
}
}

void descendingsort(int list[], int length)
{
int index, smallestindex, minindex, temp;
for (index = 0; index < length - 1; index++)
{
smallestindex = index;
for (minindex = index + 1;minindex < length; minindex++)
if (list[minindex] > list[smallindex])
smallestindex = minindex;

temp = list[smallestindex];
list[smallestindex] = list[index];
list[index] = temp;
}
}

int main()
{
double num1, num2, num3;
ifstream fin;
ofstream fout;
fin.open("scores.dat");
fout.open("results", ios::trunc);

}
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 6,143
Reputation: jwenting is just really nice jwenting is just really nice jwenting is just really nice jwenting is just really nice 
Solved Threads: 213
Team Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: fin troubles

 
0
  #2
Nov 15th, 2004
so what have you actually done to read the data?
You've declared the file, but that doesn't read the data...

Show some initiative first, try it yourself.
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 56
Reputation: jasweb2002 is an unknown quantity at this point 
Solved Threads: 2
jasweb2002 jasweb2002 is offline Offline
Junior Poster in Training

Re: fin troubles

 
0
  #3
Nov 15th, 2004
Oh, how about

fin >> some_array[whatever_index];

I think you can fill in the right names.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC