views:

60

answers:

2

The text document is TTT.txt ...in it is

X
X
X
O
-
X
O
O
-

I need my program to read each and then be able to pass it to a different part of it...HELP!

+1  A: 
char stuff[9];
FILE* foo = fopen("myfile.txt", "r");

for (int i = 0; i < 9; i++) {
    stuff[i] = fgetc(foo);
    fgetc(foo); // Ignore the newline
} // Now your characters are in "stuff"

No error handling, hardcoded file name, and uses C functions. But it does what you want in a concise format.

Borealid
Is that in c++?
Salena
@Salena, if you can't even tell if the provided solution is in C++, you may have bigger problems than we can solve here.
JSBangs
@Salena: if that question occurs to you, you should spend a little more time with either a textbook or an O'Reilly before posting on StackOverflow.
Borealid
No, that's a very good question. This is _not_ C++, it's C. And it's much harder to get right than C++ code would. Which is why it gets a `-1` from me.
sbi
+1 from me; it's not C++, but it gives an idea on what needs to be done (opening a file, reading characters into an array) without just giving away the answer.
dreamlax
@dreamlax: I would have up-voted it if it spelled this out in pseudo code.
sbi
+1  A: 

Since this is homework, I'm not going to post actual code. but I'll give you a hint into the right direction.

What you need is file streams. You can read from a file using std::ifstream. It has several methods of reading. The one your looking for is probably operator >> reading into a char.

Read up on it, try to start off, and come back here when you get stuck, showing us what you have done so far and why you got stuck.

sbi