Find the substring of the given string

This program accepts string from user as input.After accepting the string,it finds the substring of string as per the position and length.

In this program,the variable str accepts input.Also,the position and length of extrating the string are also accepted as input and stored in variable pos and len respectively.If pos is greater than len ,then the position is invalid.Here each and every character is considered and '\0' represents the end of the string.The string is extracted and stored in variable sub.

#include < stdio.h >
#include < conio.h > 
void main()
{
	char str[100],sub[100];
	int pos,len,slen,p,j,max_ext;	
	clrscr();
	printf("\nEnter a string \n");
	gets(str);
	printf("\nEnter a position :");
	scanf("%d",&pos);
	printf("\nEnter a length:");
	scanf("%d",&len);	
	//.... find strlength ...	
	for(slen=0; str[slen] != '\0' ; slen++);	
	if ( pos > slen )
	{
		printf("\nInvalid position ");
		exit(0);	
	}
	max_ext = slen -pos + 1;
	if ( len > max_ext)
	{
		printf("\nInvalid substring length ");
		exit(0);	
	}
	p = pos - 1;
	for(j=0; j < len ; j++)
	{
		sub[j] = str[p];
		p++;	
	}
	sub[j] = '\0';
	printf("\n substring = %s",sub);
} // main