#include "h/string.h"

char* pointEndString(char* instr)
{
	// returns pointer to the end of the string
	while((*instr)!='\0')
	{
	instr++;
	}
	return instr;
}

char* appendString(char* first, char* second, int maxsize)
{
	// append second string to the end of first string (maximum maxsize characters)
	char* outstr;
	int i;

	outstr=pointEndString(first);
	i=(outstr-first);
	while((i<maxsize)&&((*second)!='\0'))
	{
	*outstr++=*second++;
	i++;
	}
	*outstr='\0';
	return first;
}

char* copyString(char* first, char* second)
{
	// copy second string to first
	while((*second)!='\0')
	{
	*first++=*second++;
	}
	*first='\0';
	return first;
}

char* copyStringLimited(char* first, char* second, int maxsize)
{
	// copy second string to first up to maxsize characters
	int i;

	i=0;
	while((i<maxsize)&&((*second)!='\0'))
	{
	*first++=*second++;
	i++;
	}
	*first='\0';
	return first;
}
