Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Input/Output files

Status
Not open for further replies.

jwdcfdeveloper

Programmer
Mar 20, 2001
170
US
Ok, here's my situation. I need to read floating point values from a file, use a sort algorithm to put the values in numerical order, and then print the values out to the same file of the original values. I need three functions:

1. A function to read the values from the file
2. A function to write the reshuffled values to the file
3. A function to put the values into numeric order (main)


I know the basic code needed to do this, but I am having problems setting up the functions so that I can call the read/write functions in the main function. Anyone have any ideas about how this is set up?
 
It's not advance but a bubble sort works quite well depending on the number of posts to sort. The bubble sort is like this:

float Tabel[1000], Swap;
int Counter;
BOOL Not_Finished;
do
{
Not_Finished = true;
for(Counter = 0;Counter < Number_Of_Entrys - 1;Counter++)
{
if(Tabel[Counter] > Tabel[Counter + 1])
{
Swap = Tabel[Counter];
Tabel[Counter] = Tabel[Counter + 1];
Tabel[Counter + 1] = Swap;
Not_Finished = false;
}
}
}
while(Not_Finished);

To read and write the floats there is a quite recent thread about that.

Totte
 
hey,

to go to string:

double answer1,n1,n2;
string t1;
stringstream stream;
answer1=n2-n1;
stream << answer1; // this changes it from double to string; shove it into the stream
t1 = stream.str(); // inserts a string of t1
//*************************************
to go back to double
n1=atof(t1.c_str());

FYI: Make sure that &quot;n1&quot; in my case is a double. If it is a float it will not take the decimals.

This message is a natural product made from recycled electrons. The slight
variations in spelling and grammar enhance its individual character and
beauty and in no way are to be considered flaws or defects.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top