Reading a random text line into array

Hello, I have some problems with my school project. I am trying to make a simple hangman game, but I fail already at the beginning.
I have a text file with some words or sentences. Each line consists of 25 characters, either A-Z or dots, separated by spaces. The lines are separated by enter. So far, there are 3 lines, so the it looks approximately like this:

T H I S . I S . W O R D . O N E . . . . . . . . .
T H I S . I S . W O R D . T W O . . . . . . . . .
T H I S . I S . W O R D . T H R E E . . . . . . .

The thing I am trying to do is to load all the 25 characters of a random line into a multidimensional array, and then into a single-dimensional array, that would be displayed as '_' for letters and ' ' for dots. However, it always loads me just the first line. Could anybody help me? Here is the code:

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
#include <iostream>
#include <fstream>
#include <ctime>

using namespace std;

	ifstream Infile;
	char Sentence[25][3], Hidden[25], Check[25];

void Trans(char[]);

int main(){
	int x;
	srand (time(NULL));
	int j = (rand() % 3);
	
	Infile.open("C:/Users/admin/Desktop/VSB/ZPcvika/Project/words.txt", ios::in);
		for(int i=0; i<25; i++){
			Infile >> Sentence[i][j];
			Check[i] = Sentence[i][j];
	}

	Trans(Check);
	cout << endl;

	Infile.close();
	cin >> x;
	return 0;
}
void Trans(char Check[25]){
	for (int i=0; i<25; i++){
		if (Check[i] == '.')
			Hidden[i] = ' ';
		else
			Hidden[i] = '_';
	}
	for (int i=0; i<25; i++){
		cout << Hidden[i] << " ";
	}
}
¿where are you telling to the file wich line you want?
With the j integer in Sentence[i][j]...
Nope, there you are telling: "Whatever you read put it in this position of the array"
But you always start reading at the begginning of the file.
So, first I have to load the whole file into the array, and only then can I choose the random line?
I don't think you need the 2-dimensional array at all.
Try something like this.

1
2
3
4
5
for( int k=0; k <= j; k++ )
{
  for(int i=0; i<25; i++)
    Infile >> Check[i];
}
Thank you very much :) it works.
Topic archived. No new replies allowed.