473,397 Members | 2,056 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

File I/O ascending order question?

I have been working on this for a little while now im using the library <fstream> and <iostream>. The object of my program is to read two separate files that contain different amounts of random numbers for a total amount of 50 numbers in the output file. The problem that I'm having is that when I get all the numbers from the 2 files and write and append them to the output file now i dont understand how to get the output file which is a c-string to be able to sort using selection sort. I have all the numbers in the output file but I cant figure out how to use the c-string to sort by using selection sort.

Expand|Select|Wrap|Line Numbers
  1. #include <fstream>
  2. #include <iostream>
  3.  
  4. using namespace std;
  5. //void selectionsort(int [], int);
  6.  
  7. int main()
  8. {
  9.     char group1[2000];
  10.     char group2[2000];
  11.     char next[2000];
  12.  
  13.     ifstream ifs2;
  14.     ifstream ifs;
  15.     ifstream ifs1;
  16.     ofstream ofs;
  17.     ofstream ofs2;
  18.  
  19.  
  20.     ifs.open("hw1_input1.txt");
  21.     ifs1.open("hw1_input2.txt");
  22.     ofs.open("output.txt");
  23.     ofs2.open("temp.txt");
  24.  
  25.  
  26.  
  27.     while(ifs.getline(next, 2000))
  28.     {
  29.         ifs.get(group1, 2000);
  30.         ofs << group1 << "\t";
  31.  
  32.  
  33.  
  34.         ofs << next;
  35.  
  36.  
  37.     }
  38.  
  39.     while(ifs1.getline(next, 2000))
  40.     {
  41.         ifs1.get(group2, 2000);
  42.         ofs << group2 << "\t";
  43.  
  44.         ofs << next;
  45.     }
  46.  
  47.     ifs2.open("output.txt");
  48.     ifs2.get(next, 2000);
  49.  
  50.  
  51.     ifs.close();
  52.     ifs1.close();
  53.     ofs.close();
  54.  
  55.     return 0;
  56. }
  57.  
  58. /*void selectionsort(int a[], int size)
  59. {
  60.  
  61.  
  62.  
  63. }*/
  64.  
  65.  
I dont have the selection sort function in there because i cant figure out how to get it into an array so that i can sort the output file.

any suggestions are well appreciated
Jan 24 '08 #1
2 2342
weaknessforcats
9,208 Expert Mod 8TB
You will need to get your numbers into an array where each element is a number.

Then you can sort the array.
Jan 25 '08 #2
RRick
463 Expert 256MB
There are sort programs (i.e. sort in unix) that will sort a text file of numbers, but you have to be careful. Each number needs to be on its own line and any spaces play havoc with the sorting.
Jan 25 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: renster | last post by:
I have been looking at implementing the following but with a difference. http://forums.devshed.com/t47653/s.html This example uses a link which works with some code shown on the page. I have...
8
by: Siu | last post by:
Hi, is it possible to sort a XML file without using a XSLT or XSL file?? For example, my XML is: <A> <1> <3> <4> <2> </A>
6
by: sriram | last post by:
Hi, I have been seing a weird problem with db2look tool in db2 8.2 on Windows 2000 platform. When i spool the DDL using db2look, it spools the DDL in the ascending order of database objects...
1
by: Rich N | last post by:
When I open my form, I want the records already in it to be in Ascending Order based on one field. Though I keep putting them in Ascending order and then saving the form, each time I re-open the...
5
by: ????? | last post by:
I have an access query which gets data from a number of different tables. Although the tables have primary key fields, the order in which the records are returned means that none of these are in...
3
by: happy | last post by:
/* Book name : The prodessional programmers guide to C File name : E:\programs\tc\iti01\ch09\main\01setupm.c Program discription: file setuping -up -Version 01-ver01-W Logic ...
2
by: Joe | last post by:
Hi, I have an asp.net script that connects to MS Access database and displays data in a table. For some reason I am do not know how to display data say in ascending order of column1. I have...
6
by: flyaway888 | last post by:
Hey, I have a function that compares 2 arrays with 6 numbers in each and outputs the matching numbers. I have written a function that does this but I need to output the numbers in ascending order...
1
by: Orkinman34 | last post by:
Hello, I was wondering if someone could help me out on a question? You are suppose to type in 3 integers, any integers. List them in ascending order and if any of them are duplicate integers...
7
by: kwstriker299 | last post by:
Today in class, my professor posed an interesting question for us to think about before our next class. If you insert items that are in ascending order into a binary search tree, then you will build...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.