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

void get_me_a_string(int * int_array, int array_size, char * output_string, int output_string_max_size)
{
	if(!int_array || !output_string)
		return;
		
	char * aux_string = NULL;
	
	//Depending on the compiler int is 2-byte or 4 byte.
	//Meaning INT_MAX will be at most 2147483647 (10 characters + 1 '\0').
	aux_string = (char *) malloc(11);
	if(!aux_string)
		return;
	
	int i;
	int current_array_size = 0;
	for(i = 0; i < array_size; i++)
	{
		sprintf(aux_string, "%d", int_array[i]);
		current_array_size += strlen(aux_string);
		if(current_array_size < output_string_max_size)
			strcat(output_string, aux_string);
		else
			break;
	}
	
	free(aux_string);
}

int main(void) {
	int a[5]={5,21,456,1,3};
	
	int string_max_size = 256;
	char * string_from_array = NULL;
	
	string_from_array  = (char *) malloc(string_max_size);
	
	if(NULL == string_from_array)
	{
		printf("Memory allocation failed. Exiting...");
		return 1;
	}
	
	memset(string_from_array, 0, string_max_size);
	get_me_a_string(a, 5, string_from_array, string_max_size);
	
	printf(string_from_array);
	
	free(string_from_array);
	return 0;
}

