Click here to Skip to main content
15,923,789 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
Questionfunction pointers part 2 Pin
Mustafa Ismail Mustafa2-Oct-07 10:59
Mustafa Ismail Mustafa2-Oct-07 10:59 
AnswerRe: function pointers part 2 Pin
Chris Losinger2-Oct-07 11:15
professionalChris Losinger2-Oct-07 11:15 
GeneralRe: function pointers part 2 Pin
Mustafa Ismail Mustafa2-Oct-07 11:28
Mustafa Ismail Mustafa2-Oct-07 11:28 
GeneralRe: function pointers part 2 Pin
Stephen Hewitt2-Oct-07 17:27
Stephen Hewitt2-Oct-07 17:27 
AnswerRe: function pointers part 2 [modified] Pin
Stephen Hewitt2-Oct-07 13:25
Stephen Hewitt2-Oct-07 13:25 
AnswerRe: function pointers part 2 Pin
Cedric Moonen2-Oct-07 20:15
Cedric Moonen2-Oct-07 20:15 
GeneralRe: function pointers part 2 Pin
Stephen Hewitt2-Oct-07 21:40
Stephen Hewitt2-Oct-07 21:40 
QuestionSorting a value from file Pin
Herboren2-Oct-07 10:23
Herboren2-Oct-07 10:23 
So I'm trying to sort each value from a files. A user inputs a string of 8 numerals. then breaks the string down to an array and writes each element from the array to a file on each line.

So if the user inputs: 87654321

Its output in the file will be:

8
7
6
5
4
3
2
1

What I want to do is get the first integer of the file, compare it to the second and write to a new file the numbers in ascending order:

1
2
3
4
5
6
7
8

Now, I am aware of the sort() func, and would like to avoid it as much as possible. I'm trying to use the if/for/while to accomplish this task. Below is my code of what I have so far:

<code>
// fstsreamCompare.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <fstream>
#include <iostream>
#include <conio.h>
#include <string>
using namespace std;

int v;
int loop;
int aA[8];
string ns;

int _tmain(int argc, _TCHAR* argv[])
{
ofstream ouI;
ouI.open("rwB.dat");
if( ouI.fail()){
cout << "Error reading file: " << endl;
exit(1);}

ifstream inI;
inI.open("rwB.dat");
if( inI.fail()){
cout << "Error writing file: " << endl;
exit(1);}

do {
cout << "File(SORT) Input an 8-Digit numeral: "; cin >> ns;
if ( ns.length() < 8 )
{
cout << "Human Error! " << "The value is too short!" << endl;
cout << "The value: " << ns << " is " << ns.length() << " digits long." << endl;
cout << "Press any key to re-enter a valid numeral." << endl;
_getch();
system("CLS");}

else if ( ns.length() == 8)
{
aA[0] = ns[0] - '0';
aA[1] = ns[1] - '0';
aA[2] = ns[2] - '0';
aA[3] = ns[3] - '0';
aA[4] = ns[4] - '0';
aA[5] = ns[5] - '0';
aA[6] = ns[6] - '0';
aA[7] = ns[7] - '0';

for ( v=0; v<ns.length(); v++ )
ouI << aA[v] << endl;
}
} while ( ns.length() < 8 ); system("CLS");

cout << endl << "Values have been written to FILE(SORT)" << endl;
cout << "Press any key to sort the values." << endl << endl;

_getch();
return 0;
}
</code>

And thanks to David Crow I know how to convert strings to arrays Cool | :cool: .
I know how to get the first integer from the file but don't know how to get the second to begin comparing.
Keep in mind this is not a school project this is for my leisure.
AnswerRe: Sorting a value from file Pin
Stephen Hewitt2-Oct-07 13:46
Stephen Hewitt2-Oct-07 13:46 
AnswerRe: Sorting a value from file Pin
zakkas24832-Oct-07 19:14
zakkas24832-Oct-07 19:14 
AnswerRe: Sorting a value from file [modified] Pin
David Crow3-Oct-07 3:07
David Crow3-Oct-07 3:07 
GeneralRe: Sorting a value from file Pin
Herboren3-Oct-07 6:21
Herboren3-Oct-07 6:21 
Questionwhat is the difference between macro, pragma, and inline? Pin
Gofur Halmurat2-Oct-07 10:18
Gofur Halmurat2-Oct-07 10:18 
AnswerRe: what is the difference between macro, pragma, and inline? Pin
Mark Salsbery2-Oct-07 10:38
Mark Salsbery2-Oct-07 10:38 
Questionva_copy? Pin
DQNOK2-Oct-07 7:32
professionalDQNOK2-Oct-07 7:32 
AnswerRe: va_copy? Pin
Mark Salsbery2-Oct-07 8:19
Mark Salsbery2-Oct-07 8:19 
AnswerRe: va_copy? Pin
David Crow2-Oct-07 8:20
David Crow2-Oct-07 8:20 
GeneralRe: va_copy? Pin
DQNOK2-Oct-07 8:57
professionalDQNOK2-Oct-07 8:57 
QuestionHaving a the processID how to get the application instance (HINSTANCE) ? Pin
carabutnicolae12342-Oct-07 7:22
carabutnicolae12342-Oct-07 7:22 
AnswerRe: Having a the processID how to get the application instance (HINSTANCE) ? Pin
Maxwell Chen3-Oct-07 0:11
Maxwell Chen3-Oct-07 0:11 
QuestionCustom ComboBox Control - Need Advice [modified] Pin
Leslie Sanford2-Oct-07 6:45
Leslie Sanford2-Oct-07 6:45 
QuestionRe: Custom ComboBox Control - Need Advice Pin
Mark Salsbery2-Oct-07 8:21
Mark Salsbery2-Oct-07 8:21 
AnswerRe: Custom ComboBox Control - Need Advice [modified] Pin
Leslie Sanford2-Oct-07 8:25
Leslie Sanford2-Oct-07 8:25 
QuestionUsing Abstract classes Pin
Apstolo2-Oct-07 3:40
Apstolo2-Oct-07 3:40 
AnswerRe: Using Abstract classes Pin
Cedric Moonen2-Oct-07 4:00
Cedric Moonen2-Oct-07 4:00 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.