Coverting a file into a 2D array then displaying it, all 0s?

Pages: 12
So you're not doing it just to output it, but for some other reason?

To put into 2D array, do the output as in my sample code above, and read it in one char at a time, as suggested in my post above.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include <iostream>
#include <iomanip>
#include <conio.h>
#include <fstream>

//Using the standard namespace for files.
using namespace std;

//starting code for main program.
int main()
{
	// Setting the variables.
	int hold;
	char inputchar = 'x';
	double decimal[101] = {0};
	char grid[101][13] = {0};

	// Outputs a message on the screen.	
	cout << "Here are the special numbers in the range of 1-100 n";

	// Loop to create the array of the numbers in decimal form.
	for(int i = 1; i < 101; i++)
	{
		decimal[i] = 1./i;
	}

	// Inputs array into a text file
	ofstream output("output.txt");
    for(int i = 1;i < 101;i++)
    {
                output << fixed << setprecision(11); // Fix decimal places
		output << decimal[i] << endl;

	}

	// Converts the text file into a 2D array
    ifstream infile("output.txt");
	for (int i = 1; i < 101; i++)
	{
          for (int j=0; j<13; j++)
          {
            infile >> inputchar;
            grid[i][j] = inputchar;
          }
          
		
	}

	// Displays the array
	for (int i = 1; i < 101; i++)
	{
          for (int j=0;j<13;++j)
          {
            cout << grid[i][j];
          }
          cout << endl;
        }




// Holds the screen up.
cin >> hold;

// Returns a value to end the code.
return(0);
}


Last edited on
Thank you i see where i was going wrong now :) now i just need to check for number patterns.
Topic archived. No new replies allowed.
Pages: 12