This is a program that reads data from a disk and outputs data to the same disk.
The data is:
@2,89#3,*67
$187,3#34,72#123#
*3*7*1#*3,4,8
The program must exclude the symbols & just output the digits with the '#' starting a new line.
Output should be:
289
367
1873
3472
123
371
348
#include <fstream>Code:C++
#include <iostream>
#include <cctype>
using namespace std; //introduces namespace std
char const nwln = '\n';
int main ( )
{
char ch;
ifstream data;
ofstream dataout;
int n;
int sum;
int digit;
data.open ("a.\\data.txt");
if (!data)
{
cout << "ERROR -- Cannot open data.txt for input";
return 1;
}
dataout.open ("a:\\dataout.txt");
if (!dataout)
{
cout << "ERROR -- Cannot open dataout.txt for output";
return 1;
}
data.get(ch);
while (data)
{
digit = 0;
while ((ch != '\n') && data)
{
if (isdigit(ch))
digit = ch - '0';
sum = sum*10 + n;
}
if (ch == '#')
dataout.put(sum);
sum = 0;
}
data.close(); dataout.close();
return 0;
}
The program compiles fine (with no errors), but it doesnt print my output to the output file on the disk. Please help & tell me what I am doing wrong. This is my 1st program assignment so I am not at all experienced in c++. Thanks in advance.