Feed a multi-dim. array with getline
Hi,
Here's the code I've been working on for my Chinese character look up program. Please remember I'm a rookie, teaching myself c++ :P I did get a book but it's too limited as far as getline() and multi-dimensional arrays. What's the best way to feed a multi-dimensional array with getline() reading a text/data file?
BTW, thanks Pelp for the help on reading data into a one-dim. array.
Code:
#include <fstream.h>
#include <iostream.h>
#include <conio.h>
void FeedRadArray(int numrad_strokes);
void DisplayRads(int numrad_strokes);
using namespace std;
const int MaxRadsInRow = 51;
int main()
{
int ns,
remaining_strokes,
rad_choice,
char_choice;
cout<<"How many strokes are there in the radical? "<<endl;
cin>>ns;
FeedRadArray(ns);
/* send ns to a function that reads the radicals
from the file into the radical array */
cout<<endl<<"Please choose from the following radicals:"<<endl;
cin>>rad_choice;
// cout<<"You chose "<<y<<". "<<radindex??[y]<<endl;
cout<<"How many strokes are there in the rest of the character? "<<endl;
cin>>remaining_strokes;
// DisplayHanzi(rad_choice, remaining strokes);
/* Send rad_choice and remaining_strokes to a function that displays the radical and
the characters under that radical with that many remaining strokes */
cout<<"Which of the following is the character you're looking for? ";
cin>>char_choice;
// LookUpChar(choose_char);
return 0;
}
void FeedRadArray(int numrad_strokes)
{
char radindex[12][MaxRadsInRow];
ifstream a_file("c:\\Downloads\\C_Source\radicals3.txt"); //opens the file for reading
a_file.getline(radindex, MaxRadsInRow);
while (a_file)
{
a_file.getline(radindex, MaxRadsInRow);
}
DisplayRads(numrad_strokes);
cout<<endl;
a_file.close(); //don't forget this!
}
void DisplayRads(int numrad_strokes)
{
int x = numrad_strokes - 1; //PREPARES numrad_strokes FOR USE IN ARRAY
for(int y=0; y<=MaxRadsInRow; y++)
{
if (y % 2 != 0)
cout<<y+1<<". "<<radindex[x][y];
else
cout<<" "<<y+1<<". "<<radindex[x][y];
}
}
Thanks for any tips/suggestions you can throw my way.