I was given the following problem at a job interview and 2 hours to complete it:
Write a program to find all the sentences, or consecutive sequence of sentences, in a text file where: min <= length <= max.
Assume that a sentence ends in a period, question mark, or exclamation point. There is no fixed limit on the length of a line in the file or a practical max number of lines in the file. Count all blanks and punctuation. Include the trailing space after each sentence, but assume there is ever only one blank between sentences. (All EOL/null characters should be converted to blanks as well).

The output of the program should be sent to another text file and be sorted in ascending order based on the ASCII value of the first character of each line in the output.
Precondition: Min and Max will be positive integers less than 1000, and Min <= Max.
The name of the input and output text file is to be provided as a command line argument (not read from Standard Input or written to Standard Output).

Example Usage: program.exe <min> <max> <input file> <output file>

For example, given this input text:
Black is white. Day is night. Understanding is ignorance.
Truth is fiction. Safety is danger.


If min = max = 16 then the output is
Black is white.
If min = max = 18 then the output is
Safety is danger.
Truth is fiction.

If min = 30 and max = 37 then the output is

Black is white. Day is night.
Truth is fiction. Safety is danger.

because the two sentences are consecutive sentences with the desired length.


I'm still having a tough time wrapping my head around what is being asked and how to approach it. This is what I came up with at the end of the 2 hours:
Code:
#include <iostream>

#define MAXSIZE 1000


int ParseSent(const char *str, int *lengths, char **sents);
void initStr(char *str, int size);

using namespace std;

int _tmain(int argc, char* argv[])
{
	int lengths[MAXSIZE/2];
	int numSents, running_count;
	char string[MAXSIZE + 1];
	char outstr[MAXSIZE + 1];
	char *sents[MAXSIZE/2];

	if (argc != 5){
		printf("Usage: %s <min> <max> <input_file> <output_file>\n", argv[0]);
		return 1;
	}
	int min = atoi(argv[1]);
	int max = atoi(argv[2]);

	FILE *infile = fopen(argv[3], "r");
	if (infile == NULL){
		printf("Error: Could not open input file %s\n", argv[3]);
		return 1;
	}

	FILE *outfile = fopen(argv[4], "w");
	if (outfile == NULL){
		printf("Error: Could not create output file %s\n", argv[4]);
		fclose(infile);
		return 1;
	}
    

	while (!feof(infile)){
		fread(string, MAXSIZE, 1, infile);
		numSents = ParseSent(string, &lengths[0], sents);
		running_count = lengths[0];
		initStr(outstr, MAXSIZE + 1);
		for (int i = 0; i < numSents; i++){
			if ((running_count >= min) && (running_count <= max)){
				sprintf(outstr, "%s ", sents[i]);
				running_count += lengths[i+1];
			}
		}
		if (outstr[0] != NULL)  // something to write?
		    fputs(outstr, outfile);
	}
   
	fclose(infile);
	fclose(outfile);
	return 0;
}



int ParseSent(const char *str, int *lengths, char **sents){
	int sent_count = 0;
	int len_count = 0;
	while (*str != '\0') {  // end of line, Null inserted by fgets()
		if ((*str == '.') || (*str == '!') || (*str == '?')){
			*lengths++ = len_count;
			len_count = 0;
			sent_count++;
		}
		sents[sent_count][len_count] = *str++;
		len_count++;
	}
	*lengths++ = -1;
	return sent_count;
}


void initStr(char *str, int size){
	int count = 0;
	while (count < size){
		*str++ = '\0';
	}
}
Was I even on the right track? I'm curious what approaches you would have taken to solve this (i.e. using a Sentence Class to store each sentence along with it's length and index).
If anyone has the solution, could you kindly share it? I did find a very similar question (only missing the sort alphabetically part) over here under "Moderate Problems": http://users.csc.calpoly.edu/~jdalbe...gPractice.html