Program won't read file

So I'm having trouble with this program. I have the code below. Basically I first need to read words from this file into an array and then read from a different file and compare the words. I have narrowed down the problem and have simplified code below (this is not what the program will look like) of attempting to write the second file onto the screen but it just gives me blank spaces. I've determined that the problem is in the first for loop with "n>168". When I use "n>167" in the first array and run the program everything in the second array prints onto the screen just fine. But with "n>168" in the first array, when I print out from the second array I get nothing. I need to use "n>168" to read all the words from the first file but it makes my second one not work. Why would it do this?

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 <iomanip>
using namespace std;

struct StringPair
{	char originalWord[20];
	char replacementWord[20];
};


int main()
{	int number;
	StringPair word; 
	char wordArray[200][20];
	
	ifstream fin;
	ofstream fout;
	fin.open("codebook.txt");
	fin >> number;
	for (int n=0; n<168; n++)
	{	fin >> wordArray[n];
		cout << wordArray[n] << " ";

	}
	fin.close();
	
	fin.open("plaintext.txt");

	for (int n=0; n<200; n++)
	{
		fin >> word.originalWord;
		cout << word.originalWord << endl;
 
	}
	


	return 0;
}
to open the file it must be located at same place as your program exe.
or use path-to-file in your fin.open(); method to open it.
Topic archived. No new replies allowed.