Program description:

To be edited...

Your code:

Make file

bstsort: bstsort.c
	gcc -o bstsort bstsort.c -I.
clean:
	rm *.o *.err

.c File

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "bstsort.h"


int main(int argc, char **argv){
	
	extern char *optarg;
	extern int optind;
	int c, err = 0; 
	int cflag=0, oflag=0;
	char *string, input[100];
	FILE *infile, *outfile;
	struct BinaryNode* node = NULL;
	static char usage[] = "usage: % bstsort [-c] [-o output_file_name] [input_file_name]";

	//check command line input
	while ((c = getopt(argc, argv, "co")) != -1)
		switch (c) {
		case 'c':
			cflag = 1;
			break;
		case 'o':
			oflag = 1;
			break;
		case '?':
			err = 1;
			break;
		default:
			break;
		}
	
	//if err
	if (err) { 
		fprintf(stderr, usage, argv[0]); //print usage
		exit(1);
	}
	
	//if no input file and no output file
	if(argv[optind] == NULL){
		
		printf("Please input your sentence(s):\n");
		while(fgets(input, sizeof input, stdin) && input[0] != '\n'){ //get data from standard input
			string = (char*) malloc(sizeof(input));
			strcpy(string, input);
			insert(string, &node, cflag);
		}
	}

	//if input file and no output file
	else if (argv[optind] != NULL && oflag == 0){
		
		infile = fopen(argv[optind], "r"); //open input file to read
		
		if(!infile){ //if input file null
			printf("Error with the file.\n");
			fprintf(stderr, usage, argv[0]); //print usage
			exit (100);
		}
		else{ //if input file is not null
			while(fgets(input, sizeof input, infile) && input[0] != '\n'){ //get data from input file
				string = (char*) malloc(sizeof(input));
				strcpy(string, input);
				insert(string, &node, cflag);
			}
			
			fclose(infile); //close input file
		}
		
	}
	
	//if output file
	else if (argv[optind] != NULL && oflag == 1){
		
		outfile = fopen(argv[optind], "w"); //open output file to write
		
		if(!outfile){ //if output file null
			printf("Error with the file.\n");
			fprintf(stderr, usage, argv[0]); //print usage
			exit (100);
		}
		
		//if input file
		if(argv[optind + 1] != NULL){
			infile = fopen(argv[optind + 1], "r"); //open input file to read
			if(!infile){ //if input file null
				printf("Error with the file.\n");
				fprintf(stderr, usage, argv[0]); //print usage
				exit (100);
			}
			
			//if input file not null
			else{
				while(fgets(input, sizeof input, infile) && input[0] != '\n'){ //get data from input file
					string = (char*) malloc(sizeof(input));
					strcpy(string, input);
					insert(string, &node, cflag);
				}
				
				fclose(infile); //close input file
			}
		}
		
		//if no input file
		else{
			printf("Please input your sentence(s):\n");
			while(fgets(input, sizeof input, stdin) && input[0] != '\n'){ //get data from standard input
				string = (char*) malloc(sizeof(input));
				strcpy(string, input);
				insert(string, &node, cflag);
			}
			
		}
	}
	
	inorderSort(node, outfile, oflag); //call inorder sort function
	postorderFree(node); //call postorder traversal free tree function
	exit (0);
}

All the assignments will be posted. Subscribe for more! :)