tweak 0 #26 December 16, 2004 Wow, more fun for the fam! I found an old copy of Stroustrup's book (third edition, 97) and it does say that if the var is declared in the initializer of the for loop it loses scope at the end of that for loop. Geez! I'm feelin' geeky tonight. It's a good thing I'm sure I threw away the second edition or I'd probably be digging around in the closet for it... Quote Share this post Link to post Share on other sites
bob.dino 1 #27 December 16, 2004 Hah . I don't own a copy of Stroustrup. Does this mean I can't call myself a C++ programmer . Still, time for me to go back to web services in J2EE. I don't think I've ever seen so many configuration files to set up something so simple... Quote Share this post Link to post Share on other sites
tweak 0 #28 December 16, 2004 Actually what I was trying to say was that the variable being declared in the initializer list of the for loop and not inside the braces of the for loop is why I thought it would be in scope until the end of block surrounding the for loop. I didn't notice she didn't have braces. Quote Share this post Link to post Share on other sites
tweak 0 #29 December 16, 2004 Actually I haven't picked up a C++ book in years, usually if I can't remember something I can find it in the MSDN lib or Google groups. It's funny, I think the only time anyone in our group ever picks one up is to end an argument! Quote Share this post Link to post Share on other sites
Remster 30 #30 December 16, 2004 Mar is gonna be all hot and bothered now... all this ubergeek talk... lolRemster Quote Share this post Link to post Share on other sites
Morcyk 0 #31 December 16, 2004 Ok... with some slight mods... const MAX_LENGTH_OF_NAMES = 21; const NUMBER_OF_LAST_NAMES = 50; char namesArray[NUMBER_OF_LAST_NAMES][MAX_LENGTH_OF_NAMES]; void openInput( ifstream *); void loadArray( ifstream *, char[][MAX_LENGTH_OF_NAMES]); void main() { ifstream *infile = new ifstream(); openInput( infile ); loadArray( infile, namesArray ); delete infile; infile = NULL; } //---------------------------------------------------------------------- void openInput( ifstream *input ) //---------------------------------------------------------------------- { input->open("input.txt"); if(input == NULL) { cerr << "Error opening input file!" << endl; exit(1); } } //---------------------------------------------------------------------- void loadArray( ifstream *input, char array[][MAX_LENGTH_OF_NAMES] ) //---------------------------------------------------------------------- { int i = 0; if (input != NULL) { do { input->getline( array, 80, ',' ); cout << "Yo!" << array << endl; i++; } while (!input->fail()); } } this works in VC++6. The changes I made were to make the infile variable a pointer and changed the function declarations that take it as input so that they expected a pointer instead. Changed the '.' in all the input calls to be a '->' Changed the check for whether input didn't exist to be checking to see if it was NULL. Added a delete to the main to free the memory. In loadArray, you had i declared, but never used. the input.getline function expects a char* for the first parameter. a char[][] is NOT a char*. You need to index that array to use it as one. So I changed the call to input.getline to say array and also did it in your cout statement. hmm something goofy is happening with the forum here. that part about the change to array should say array '['i']'.... it's stripping my brackets and the i for some reason. Quote Share this post Link to post Share on other sites
Dutchboy 0 #32 December 16, 2004 If you are using C++, why aren't you taking a ref to the ifstream, and why aren't you using the standard string object. Also a function that returns nothing and has no exceptions possibly thrown is worthless. You wouldn't want to turn this in to my high school C++ class. Quote Share this post Link to post Share on other sites
bob.dino 1 #33 December 16, 2004 Square brackets are UBB (the bastardised-cousin-of-html code that allows you to put smiley faces into your messages). [_i_ ] without the underscores puts the text into italics - like using in HTML. I don't know how to escape it, unfortunately. Quote Share this post Link to post Share on other sites
Morcyk 0 #34 December 16, 2004 They teach C++ at your high school?! All they had for us was gw-basic. Quote Share this post Link to post Share on other sites
indyz 1 #35 December 16, 2004 QuoteI don't know how to escape it, unfortunately. Put a period as the first character inside the brackets. For example, [..i] shows as [.i] Quote Share this post Link to post Share on other sites
bob.dino 1 #36 December 16, 2004 Nice. Thanks. (I couldn't find it on google). Quote Share this post Link to post Share on other sites
br0k3n 0 #37 December 16, 2004 QuoteNice. Thanks. (I couldn't find it on google). Are we bored at work today Dave ok let me clear this up once and for all... I have edited to the orginal code and believe that this is best solution. 10 MODE 2 20 COLOUR RND(7)+1 30 PRINT "Oli is a Skygod "; 40 GOTO 30----------------------------------------------------------- --+ There are 10 types of people in the world: Those who understand binary, and those who don't.. --+ Quote Share this post Link to post Share on other sites
bob.dino 1 #38 December 16, 2004 How did you guess?! Quote Share this post Link to post Share on other sites
Dutchboy 0 #39 December 16, 2004 QuoteThey teach C++ at your high school?! All they had for us was gw-basic. It is a private high school. Last year I taught aviation there as well. Next year I won't be teaching there at all since the pay stinks and I have a baby on the way. Quote Share this post Link to post Share on other sites