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.h>Code:c++
#include <iostream.h>
#include <cctype>
using namespace std; //introduces namespace std
char const nwln = '\n';
int main ( )
{
char ch;
ifstream data;
ofstream dataout;
int n;
int sum;
data.open ("a.\\data.txt");
if (!data)
{
cout << "ERROR -- Cannot open data.txt for input" << end1;
return 1;
}
dataout.open ("a:\\dataout.txt");
if (!dataout)
{
cout << "ERROR -- Cannot open dataout.txt for output" << end1;
return 1;
}
data.get(ch);
while (data)
{ sum = 0;
cdigit = 0;
while ((ch != '\n') && data)
{
if (isdigit(ch))
cdigit = ch - '0';
sum = (sum*10) + n
dataout.put(ch);
data.get(ch);
}
if (ch == '#')
dataout << sum << end1;
sum = 0;
}
}
data.close(); dataout.close();
return 0;
}