Hello,
I build a program that reads characters, numbers and whitespace from a Input file.
It must convert this characters, numbers and whitespace to hexidecimal.
I use an array to do this.
It works succesfully until there is a whitespace in the Input file.
After the whitespace the program stops reading the rest of the Input file.
Is there a possibility to do this?
Thanks!
my code:
CODE
//-----------------------------------INFO--------------------------------------
// *.out-file parser by SD&ADC 17/04/2008
//-----------------------------------LIBRARY------------------------------------
#include "stdafx.h"
#include <conio.h>
#include <iomanip>
#include <cstdlib>
#include <string>
using std::string;
#include <fstream> // bibliotheken input file
using std::ifstream;
#include <fstream> // bibliotheken output file
using std::ofstream;
#include <cstdlib>
using std::exit;
#include <iomanip>
using std::setw;
#include <iostream>
using std::ios;
using std::endl;
using std::cout;
using std::cerr;
using std::hex;
using std::dec;
//-----------------------------------INIT------------------------------------
// TI_FILEHDR
char TI_FILEHDR[21];
int _tmain(int argc, _TCHAR* argv[])
{
//-----------------------------------INPUT FILE----------------------------------
// ifstream constructor opens the file
ifstream inInputFile( "Input.txt", ios::in );
// exit program if ifstream could not open file
if ( !inInputFile )
{
cerr << "File could not be opened" << endl;
exit( 1 );
} // end if
//-----------------------------------OUTPUT FILE-----------------------------------
// ofstream constructor opens file
ofstream outOutputFile( "Output.txt", ios::out );
// exit program if unable to create file
if ( !outOutputFile ) // overloaded ! operator
{
cerr << "File could not be opened" << endl;
exit( 1 );
} // end if
//-----------------------------------BEGIN PROGRAM----------------------------------
int waarde;
cout << "karakter" << setw(5) << "hex" << endl;
for (int x=0; x<22; x++)
{
inInputFile >> TI_FILEHDR;
cout << setw(4) << TI_FILEHDR[x];
waarde = TI_FILEHDR[x] + 0;
if (TI_FILEHDR[x] < 0) // extended ASCII
waarde = waarde - 4294967040;
//-----------------------------------END PROGRAM-----------------------------------
return 0;
}