Computing.Net > Forums > Programming > read data from a file into an array

read data from a file into an array

Reply to Message Icon

Original Message
Name: webmanc
Date: August 31, 2004 at 14:50:41 Pacific
Subject: read data from a file into an array
OS: windows
CPU/Ram: 256
Comment:

How do I open a file and read data into an array i have a file named wordfind.in this is what my file looks like below. I am attempting to read in the information in the fist paragraph into a 2 demintional array and then compare the information in the array with the string of words to see if i can find a match in the random matrix. Here is my code and what i have writen so far can any one offer help?

cenad
aatps
rnrpj
hello
wmneo

hello
apple
car
me
men
ran
woman

#include <iostream>
#include <fstream>
#include <string>
#include <cassert>

using namespace std;

int main()
{
//Greeting
cout << "\nFinds a given set of words in a square table filled\n"
"with single letters.As well as the direction in which the\n"
"word is oriented (N, NE, E, SE, S, SW, W, NW). If a word\n"
"does not occur, then the line should contain the word and\n"
"then NOT FOUND.\n";


// Delcare 2D array to hold letters

char getLetters[25][5];

// Enter in File Name
cout << "Enter the name of the input file: ";
string inputFileName;
getline(cin, inputFileName);

// Open File
ifstream inStream;
inStream.open(inputFileName.data());
assert(inStream.is_open());

for(;;)
{
inStream >> getLetters[25][5];
if(inStream.eof()) break;
}

inStream.close();



Report Offensive Message For Removal

Response Number 1
Name: wizard-fred
Date: August 31, 2004 at 16:14:07 Pacific
Subject: read data from a file into an array
Reply: (edit)

What you need is an array of 5 x 5.
When you input each line you will have to extract each character.


Report Offensive Follow Up For Removal

Response Number 2
Name: webmanc
Date: August 31, 2004 at 16:37:03 Pacific
Subject: read data from a file into an array
Reply: (edit)

i understand the part about having an array[5][5] however how do i take the charcters and place them into the 2d array.


Report Offensive Follow Up For Removal







Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: read data from a file into an array

Comments:

 


  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 
Data Recovery Software