#include "stdio.h"
#include "malloc.h"
#include "stdlib.h"
void subString(char *p, int start, int len);
void substring(char *p,int start, int len)
{
int i;
printf("取出的子串是:");
for(i = start; i < start + len; i++ )
printf("%c",*( p + i));
printf("\n");
}
int main()
{
int n, i = 0,start,len;
printf("请输入字符的个数:n,起始位:start,子串长度:n\n");
scanf("%d%d%d",&n,&start,&len);
printf("n = %d, start = %d, len = %d\n",n,start,len);
printf("请输入字符串:");
char *pstr = (char *)malloc(sizeof(char)*(n + 1));
if( NULL == pstr)
{
printf("内存分配失败\b");
exit(-1);
}
else
{
for( i = 0; i <= n; i++ )
*(pstr + i) = getchar();
*(pstr + i) = '\0';
}
printf("\n");
if(start > n || len > n)
printf("输入参数不合适\n");
else
{
substring(pstr,start,len);
}
return 0;
}
