static void Main(String[] args) { int C = 72; // Column length to wrap to String inputFilename = ""; String outputFilename = "output.txt"; //Scanner scanner = null; StreamReader readFile = null; // Read the command line arguments ... if (args.Length != 3) { PrintUsage(); //System.exit(1); Environment.Exit(1); } try { //C = Integer.parseInt(args[0]); C = int.Parse(args[0]); inputFilename = args[1]; outputFilename = args[2]; //scanner = new Scanner(new File(inputFilename)); readFile = File.OpenText(inputFilename); } catch (FileNotFoundException) { Console.WriteLine("Something is wrong with the input."); PrintUsage(); //System.exit(1); Environment.Exit(1); } // Read words and their lengths into these vectors IQueueInterface <String> words = new LinkedQueue <String>(); // Read input file, tokenize by whitespace while (!readFile.EndOfStream) { string line = readFile.ReadLine(); string[] splitWords = line.Split(' '); foreach (var word in splitWords) { words.Push(word); } } // At this point the input text file has now been placed, word by word, into a FIFO queue // Each word does not have whitespaces included, but does have punctuation, numbers, etc. /* ------------------ Start here ---------------------- */ // As an example, do a simple wrap int spacesRemaining = WrapSimply(words, C, outputFilename); Console.WriteLine("Total spaces remaining (Greedy): " + spacesRemaining); } // End main()
/** * The main program. * *@param args The command line arguments, see usage notes */ public static void Main( string[] args ) { int C = 72; // Column length to wrap to string inputFilename; string outputFilename = "output.txt"; Scanner scanner = null; // Read the command line arguments ... if( args.Length != 3 ) { printUsage(); System.Environment.Exit(1); } try { C = Int32.Parse(args[0]); inputFilename = args[1]; outputFilename = args[2]; scanner = new Scanner(inputFilename); } catch(FileNotFoundException e ) { Console.WriteLine("Could not find the input file."); System.Environment.Exit(1); } catch(Exception e) { Console.WriteLine("Something is wrong with the input."); printUsage(); System.Environment.Exit(1); } // Read words and their lengths into these vectors QueueInterface<string> words = new LinkedQueue<string>(); // Read input file, tokenize by whitespace while( scanner.hasNext( ) ) { string word = scanner.next(); words.Push( word ); } scanner.close(); // At this point the input text file has now been placed, word by word, into a FIFO queue // Each word does not have whitespaces included, but does have punctuation, numbers, etc. /* ------------------ Start here ---------------------- */ // As an example, do a simple wrap int spacesRemaining = wrapSimply(words, C, outputFilename); Console.WriteLine("Total spaces remaining (Greedy): " + spacesRemaining ); } // End main()