944,028 Members | Top Members by Rank

Ad:
  • C Discussion Thread
  • Unsolved
  • Views: 1940
  • C RSS
Nov 15th, 2004
0

fin troubles

Expand Post »
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);

}
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
toadie2004 is offline Offline
2 posts
since Nov 2004
Nov 15th, 2004
0

Re: fin troubles

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.
Team Colleague
Reputation Points: 1658
Solved Threads: 331
duckman
jwenting is offline Offline
7,719 posts
since Nov 2004
Nov 15th, 2004
0

Re: fin troubles

Oh, how about

fin >> some_array[whatever_index];

I think you can fill in the right names.
Reputation Points: 11
Solved Threads: 2
Junior Poster in Training
jasweb2002 is offline Offline
56 posts
since Sep 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C Forum Timeline: need help, fingerprint verification system
Next Thread in C Forum Timeline: writing a simple cat program





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC