//============================================================
// SubString.cpp
//
// Get all sub string of a specific string.
//============================================================
int main(int argc,char *argv[])
{
unsigned int StartPos; // The starting position.
unsigned int NumCounts; // The number amounts you need to fetch.
unsigned int StrLen; // The length of specific string.
unsigned int tmppos;
unsigned int TmpLen;
unsigned int Counts; // Total output.
int flag;
char *string;
char *temp;
char *Result;
//
Result = (char *)malloc(sizeof(char) * StrLen);
while (NumCounts < StrLen)
{
StartPos = 0;
while (StartPos < StrLen)
{
temp = SubStr(string,StartPos,1);
strcpy(Result,temp);
tmppos = StartPos + 1;
while (strlen(Result) < NumCounts && tmppos < StrLen)
{
flag = 1;
temp = SubStr(string,tmppos,1);
strcat(Result,temp);
if (strlen(Result) >= NumCounts && tmppos < StrLen )
{
if (Counts%5 == 0)
printf("\n");
printf("%s\t",Result);
Counts++;
tmppos++;
Result = SubStr(Result,0,NumCounts - 1);
}
else
tmppos++;
}
if (!flag)
{
if (Counts%5 == 0 && Counts != 0)
printf("\n");
printf("%s\t",Result);
Counts++;
}
StartPos++;
}
NumCounts++;
}
printf("\nTotal Substring is :%d\n",Counts);
return 0;
}
//============================================================
// SubStr()
//
// Get the sub string of a string
//============================================================
char *SubStr(char *str,int sPos,int cnt)
{
int strLen;
int i;
static char *tmp;
char *tmp1;