| | |
fin troubles
Please support our C advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Nov 2004
Posts: 2
Reputation:
Solved Threads: 0
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);
}
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
- MORE iPod troubles (*nix Software)
- Pointer troubles (C++)
- .exe Troubles. Help Needed. (Viruses, Spyware and other Nasties)
- BIOS troubles (Motherboards, CPUs and RAM)
- i think java troubles??.... (Java)
- Spyware troubles (Viruses, Spyware and other Nasties)
- Sound Troubles (Windows 95 / 98 / Me)
Other Threads in the C Forum
- Previous Thread: need help, fingerprint verification system
- Next Thread: writing a simple cat program
| Thread Tools | Search this Thread |
#include adobe ansi api array arrays asterisks binarysearch changingto char character cm copyimagefile cprogramme creafecopyofanytypeoffileinc csyntax database directory dynamic execv feet fgets file fork framework frequency function getlasterror givemetehcodez global grade graphics gtkgcurlcompiling hacking hardware highest histogram include incrementoperators infiniteloop input interest kernel keyboard kilometer license linked linkedlist linux linuxsegmentationfault list lists locate logical_drives looping loopinsideloop. lowest match matrix meter microsoft motherboard mqqueue number odf opensource overwrite owf pattern pdf performance pointer posix probleminc process program programming radix recursion recv repetition research reversing scripting segmentationfault sequential socket socketprograming standard string systemcall testing threads turboc unix user voidmain() wab windows.h windowsapi






