Hello Daniweb,
This is my first official "help" thread. I'm currently attempting to read a file that has the following code:
8 split 1 9 1 spare 7 2 10 strike 8 2 spare 6 split 2 7 3 spare 10 strike 10 strike 10 turkey 8 1
and have it read only the integers, like this:
8 1 9 1 7 2 1 0 8 2 6 2 7 3 1 0 1 0 1 0 8 1 1
However, as you can see, the 10's are being broken up into 1's and 0's because I'm drawing out characters.
How would I go about making it so that if a '1' is succeeded by a '0', they are displayed together without a space between them?
My code so far...
#include <iostream>
#include <fstream>
#include <cstdlib>
using namespace std;
int main()
{
//defining variables
const int MAX = 50;
char c[MAX];
char file;
//giving file names
ifstream original;
ofstream updated;
//opening input file
original.open("lane9.dat");
if(original.fail())
{
cout << "Input file was inaccessible.";
exit(1);
}
//opening output file
updated.open("MGlane9.txt");
if(updated.fail())
{
cout << "Outpur file was inaccessible.";
exit(1);
}
for(int i = 0; i < MAX; i++)
{
//end of file NOT reached before reading/writing
while(!original.eof())
{
original >> file;
if(isdigit(file))
{
c[MAX] = file;
cout << c[MAX] << " ";
updated << file << " ";
}
}
}
//closing files
original.close();
updated.close();
//closing program
getchar();
return 0;
}
Without sounding like an complete idiot in front of you guys, my original theory was to create a for loop with an if statement if the char value is equal to one, and have another if statement inside of the first one if the number after value '1' is '0'. However, before I attempt to write it, I would like to see what the pro's think. Would that be the way to go about it?