#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_N 1000

int compar(const void* string1, const void* string2) {
	const char** s1 = (const char**) string1;
	const char** s2 = (const char**) string2;
	return strcmp(*s1, *s2);
}

void sort_strings(const char* input, const char* output, unsigned int n) {
	const char* strings[MAX_N];
	size_t i = 0;
	size_t offset = 0;
	for (i = 0; i < n; i++) {
		strings[i] = input + offset;
		offset += strlen(input + offset) + 1; // + 1 for NUL
	}

	qsort(strings, n, sizeof(const char*), &compar);

	offset = 0;
	for (i = 0; i < n; i++) {
		const size_t len = strlen(strings[i]);
		strncpy((char*) output + offset, (char*) strings[i], len + 1);
		offset += len + 1;
	}
}

