Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 136,080 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,591 people online right now. Registration is fast and FREE... Join Now!




Reading whitespaces in an array

 
Reply to this topicStart new topic

Reading whitespaces in an array

SD&ADC
22 Apr, 2008 - 12:02 AM
Post #1

New D.I.C Head
*

Joined: 21 Apr, 2008
Posts: 2

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;
}


User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/1/08 07:32PM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month