435,512 Members | 3,520 Online
Need help? Post your question and get tips & solutions from a community of 435,512 IT Pros & Developers. It's quick & easy.

# Convert separate digits into one whole number...???

P: 2
Hello! I need a little more help. I have managed to convert all my chars input from a text file into digits.
Example:
Input from file:
\$1,9,56#%34,9
!4.23#\$4,983
Output:
1956
349
423
4983
Now, I need to take those individual digits the 1 9 5 6 and make it read as a whole number. The output would look the same but they would actually be whole numbers. Make sense? I have to do this in my outer loop. It also has to be an EOF loop. So, I know I need to take the first digit and multiply it by 10 and add the next digit then multiply all that by 10 until I reach the last number. How can I write that in an efficient non-crashing way?
I attached my input .txt file if you need to see it.
This is what I have so far...

THANK YOU SOOOO MUCH!!!
Expand|Select|Wrap|Line Numbers
1. /*
2.  */
3.
4.  //Character Processing Algorithm
5.
6.  #include <fstream>
7.  #include <iostream>
8.  #include <cctype>
9.  using namespace std;
10.
11.  char const nwln = '\n';
12.
13.   int main ()
14.    {
15.      ifstream data;
16.      ofstream out;
17.      char ch;
18.      char lastch;
19.      int sum;
20.
21.      data.open ("lincoln.txt"); //file for input
22.      if (!data)
23.         {
24.         cout << "Error!!! Failure to Open lincoln.txt" << endl;
25.         system ("pause");
26.         return 1;
27.         }
28.      out.open ("out.txt"); //file for output
29.      if (!out)
30.         {
31.         cout << "Error!!! Failure to Open out.txt" << endl;
32.         system ("pause");
33.         return 1;
34.         }
35.
36.      data.get (ch); // priming read for end-of-file loop
37.
38.      while (data)
39.            {
40.            sum = 0;
41.            while ((ch != nwln) && data)
42.                  {
43.                  if (isdigit(ch))
44.                     out<<ch;
45.
46.                  if (ch == '#')
47.                     out<<endl;
48.                  {
49.                  ;
50.                  }
51.
52.                                   lastch = ch;
53.                  data.get (ch); // update for inner loop
54.                  } // inner loop
55.                  if (lastch != '#')
56.                      out<<endl;
57.
58.
59.
60.               data.get (ch); // update for outer loop
61.
62.            } //outer loop
63.
64.      cout << "The End..." << endl;
65.      data.close (); out.close ();
66.      system ("pause");
67.      return 0;
68.      } //main
69.
70.
71.
72.
73.
74.
75.
76.
77.
78.
79.
80.
81.
82.
83.
84.
85.
86.
87.
88.
89.
90.
91.
92.
93.
94.
95.
96.
97.
98.
99.
100.
Attached Files
 lincoln.txt (44 Bytes, 290 views)
Feb 12 '11 #1