
April 15th, 2001, 03:22 AM
|
|
Junior Member
|
|
Join Date: Apr 2001
Location: South Africa
Posts: 0
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
I was just wondering if there is a more efficient way to write this program...
The program basically accepts command line arguments which are option flags followed by the option (eg: -d documentName). I then parse argv and separate them into variables. Then I open a file. Then I have a while loop that reads a line at a time from the file and splits the line into several components, storing them in variables. Then I check whether a few the regular expression given on command line match the variables. If they do, I print that line and depending on the command line args, I print it a certain way.
I have a lot of "if-else" statements inside the while loop. I think I should be able to make it more efficient but I can 't think how. For example: the way in which i have to print the lines is fixed from when the program is started. So is there a way I could not check every time round the while loop, which way I am supposed to be printing before I print?
|