Hi, I need help writing a program that allows you to read an English-French dictionary into two arrays. The English words are stored in one file alphabetically while the French words are stored in the other file corresponding to the English words. This means that the program would ask the user to type a random word and then it would print its French equivalent. The dictionary has to store up to 50 words and use the following function prototypes:

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);

I'm using Word Length equals to 30. This is what I have so far:

#include <iostream>
#include <fstream>
#include <string>
using namespace std;
const int max_word_len = 30;
int read_in(char[][max_word_len], char[][max_word_len]);
void sort_words(char[][max_word_len], char[][max_word_len], int);
void search_words(char[][max_word_len],char[][max_word_len], int);
void write_out(char[][max_word_len],char[][max_word_len], int);
int main () 
{
	const int max_word_count = 50;
	char english[max_word_count][max_word_len];
    	char french[max_word_count][max_word_len];
    	int word_count = read_in(english, french);
	string line;
	ifstream myfile;							
	ofstream outfile;							
	myfile.open("English.txt");
	if (myfile.is_open())
	{
		while (myfile.good())
		{
			getline (myfile,line);
			cout<<line<<endl;
		}
		myfile.close();
	}
	else cout << "Unable to open the file"; 
	return 0;
}

I know it's not complete, I'm trying to tackle each function one at a time but I'm sure how to proceed next. I would appreciate any help. Thank you.

It would be alot simpler if you stored the words in a structure so that the English and French words can be kept together.

struct words
{
    char English[max_word_len];
    char French[max_word_len];
}

Then make an array of structures struct words array[40]; You might also have to change the functions to accept array of structures void sort_words(struct words array[], int nitems);

Or better yes using an std::vector of std::strings could make life easy-peazy, no?

Or better yes using an std::vector of std::strings could make life easy-peazy, no?

Not really. That's not much different than what he now has. a std::vector of structures or classes would work.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.