Here is what I have:

} else if ( argc > 1 ){
    
	for ( int arg = 1; arg < argc; ++arg ){
	    
	    infile.open( argv[arg] );
	    
	    if ( infile ){
	    
		list = read_file( &infile, &lines );   
	    
	    }
     
	}
	
    }

argv[1] = text.txt gets opened, but argv[2] = text2.txt does not. Why would this be?

command line: sortIt text.txt text2.txt

if I do sortIt text2.txt text.txt then text2.txt opens and text.txt does not.

Any help would be appreciated. Thanks.

>>Why would this be?
Because after that read operation you have to close the file and clear the errors.

if ( infile ){
	    
		list = read_file( &infile, &lines );   
	        infile.close();

}

I did this and I still get the same result.

When I cout << infile I get an address the first time and 0 the next time.

tazboy,
Post complete source code.

if ( infile ){
	    
		list = read_file( &infile, &lines );   
	        infile.close();

}

I did this and I still get the same result.

When I cout << infile I get an address the first time and 0 the next time.

Ancient Dragon already said you needed to clear the errors too. If you read an ifstream to the very end, the eofbit is set and won't let you do any more reading even if you close the file and open another one. The two states are separate. After closing, clear the error state:

list = read_file( &infile, &lines );   
infile.close();
infile.clear();

Ok, I did infile.clear() and it didn't work. But then I got rid of a few debugging lines and now it works. We never talked about infile.clear() in class so I never knew it existed. Thanks everyone.

We never talked about infile.clear() in class so I never knew it existed. Thanks everyone.

You need to start reading you textbook :)

Only if you buy it.

Only if you buy it.

Why do you bother going to college if you are not going to buy the textbooks? Just how to you expect to learn? Professions don't always tell you everything you need to know in order to complete the assignments, they expect you to read and study too. Yes I know those text books are very expensive, sometimes too expensive. The schools I know about have used books at discounted prices also. You can even check the libraries to see if they have it.

commented: Good advice. +7

I was actually kidding around. I guess I should have done

"Only if you buy it. ;)"

I have a few books on c++.

commented: I am not kidding. -1
commented: Don't act like a loser. -3

They are two different subjects. This one was on opening files and the other one is on array of pointers.

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.