Hi, I just started to learn C 5 hours ago.
I tried to build a simple function that simulates the substr() function of JavaScript, php, etc.

now lets look at the problem:
let me say, my string is: I S A A C.
and I make sub(mystr, 0, 2).
Ok, the program write's me: ISA (Until here its all ok..) and a lot of @#$%^& (This is the problem).

Now, I know that is because the others characters didnt received any value, but I havent any idea how to solve the problem.

The code:
Code:
#include <stdio.h>
#include <conio.h>

int strll(char str[10]);
void sub(char string[10], int min, int max);

int main()
{
	char str[10];
	printf("String: ");
	gets(str);
	printf("\n");
	sub(str,0,2);
	
	return 0;
}

int strll(char str[10])
{
	int i;

	for(i = 0; str[i] != '\0'; i++);
	return i;
}

void sub(char string[10], int min, int max)
{
	char strcp[10];
	int i, j;
	j = 0;

	for(i = min; i <= max; i++)
	{
		strcp[j] = string[i];
		j++;
	}
		
	printf("%s",strcp);
}
or : http://scripter.fresh.li/substr.txt

Thanks,
Isaac.