#include <stdio.h>
#include <string.h>

const int MAX_LEN= 256;
const int NO_STRINGS= 10;

int main(int argc, char ** argv)
{
	char strings[NO_STRINGS][MAX_LEN]; // Strings contain input
	char tmp_string[MAX_LEN];		// For swapping in sort routine
	int changed= 1;					// For bubblesort
	int i;


	// Input the strings
	for (i= 0; i < NO_STRINGS; i++) {
		printf ("Please type string %d\n",i);
		fgets(strings[i],MAX_LEN, stdin);
	}

	// Sort the strings using a bubblesort
	
	while (changed) {  // Keep sorting until no more changes are made
		changed= 0;
		// Compare all adjacent strings
		for (i= 0; i < NO_STRINGS -1; i++) {
			// See library printouts for how strcmp works
			if (strcmp(strings[i], strings[i+1]) > 0) {
				strcpy (tmp_string, strings[i+1]);
				strcpy (strings[i+1], strings[i]);
				strcpy (strings[i],tmp_string);
				changed= 1;
			}
		}
	}
	printf ("\n\nPrinting sorted strings\n");

	// Printout strings
	for (i= 0; i < NO_STRINGS; i++) {
		printf ("%s",strings[i]);
	}
	return 0;

}
