french/english dictionary read file problems

My girlfriend put this code together for a class to create a french/english dictionary. I'm not good with the char stuff as I never deal with chars or open files. The two major errors is the while loop for the infile, and the char part of the file in the function at the bottom.
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
68
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
 //Assignment #1

#include<iostream>
#include<fstream>
#include<string>
#include<iomanip>

using namespace std;

const int WORD_LENGTH = 30;
const int MAX_WORDS = 50;
//int n = 0; 

int read_in(char[][WORD_LENGTH], char[][WORD_LENGTH]);
void sort_words(char[][WORD_LENGTH], char[][WORD_LENGTH], int);
void search_words(char[][WORD_LENGTH], char[][WORD_LENGTH], int);
void write_out(char[][WORD_LENGTH], char[][WORD_LENGTH], int);

void  main()
{
	char english[MAX_WORDS][WORD_LENGTH];
	char french[MAX_WORDS][WORD_LENGTH];
	int numOfElements = 0; 
	int sum = 0;
		
	read_in(english, french, numOfElements);
	sort_words(english, french, numOfElements);
    search_words(english, french, sum);
    write_out(english, french, sum);
	
	system("pause");
	
}


int read_in(char newEnglish[][WORD_LENGTH], char newFrench[][WORD_LENGTH], int numOfElements)
{   
	char str1[MAX_WORDS];
	char str2[MAX_WORDS];
		
	ifstream inFile;
	inFile.open("dict.dat");
	
	if(!inFile.open("dict.dat"))
	{
		std::cout << "There was an error opening the dictionary." << endl; 
		}
	
	for(int i = 0; !inFile.eof(); i++)
	{
		inFile >> str1 >> str2; 
		strcpy(newEnglish[i], str1);
		strcpy(newFrench[i], str2);  
		numOfElements = i;
		return numOfElements;
	}
}

void sort_words(char newEnglish[][WORD_LENGTH], char newFrench[][WORD_LENGTH], int sum)
{ 
	int	i, j, k; 
	char str1[MAX_WORDS];
	char str2[MAX_WORDS];
	
	for	(i = 0; i < sum-1 ; i++)
	{	
		for(j = 0 ; j < sum-1 ; j++)
		{
			for(k = 0; k < WORD_LENGTH; k++) 
			{
				if(newEnglish[j][k] - newEnglish[j+1][k] < 0) 
				{
					break;
				}
				else if(newEnglish[j][k] - newEnglish[j+1][k] > 0)
				{
					strcpy(str1, newEnglish[j]);
					strcpy(str2, newFrench[j]);
					strcpy(newEnglish[j],newEnglish[j+1]);
					strcpy(newFrench[j],newFrench[j+1]);
					strcpy(newEnglish[j+1],str1);
					strcpy(newFrench[j+1],str2);
					
				}
				else
				{
					continue;
				}

			}
		}
	}
}


void search_words(char newEnglish[][WORD_LENGTH], char newFrench[][WORD_LENGTH], int sum)
{
	char answer; 
	char str[MAX_WORDS], search[MAX_WORDS][WORD_LENGTH], 
	int i = 0; 

	while(answer == 'Yes' || answer = 'yes' || answer = 'Y' || answer = 'y')
	{
		cout << "Please enter an English word you would like to translate to French."; 
		cin >> str;
			strcpy(search[0], str);
			for(i=0; i<sum; i++)
			{
				if(strcmp(newEnglish[i], search[0]) == 0)
				{ 
					cout<<setw(30)<<right;
					cout<<"The French translation is: "<<newFrench[i]<<endl; 
				}
				
				else
				{
					cout<< "This word is not in this English dictionary. Would you like to try another word?" <<endl;
					cin>> answer;
					cout<< endl;

				}
			}
	}

}



void write_out(char newEnglish[][WORD_LENGTH], char newFrench[][WORD_LENGTH], int sum)
{
		int i = 0;
		ofstream outFile;
		outFile.open("OUT.TXT");	
		for (i=0;i<sum;i++)	
		{   		
			outFile<<newEnglish[i]<<" \t "<<newFrench[i]<<endl;	
		}	
		
		outFile.close();	

}
Topic archived. No new replies allowed.