#include <stdio.h>
#include <string.h>
#include <malloc.h>
char* substring(char*, int, int);
main()
{
char string[100], *pointer;
int position = 1, length = 1, temp, string_length;
printf("Enter a string\n");
gets(string);
temp = string_length = strlen(string);
printf("Substring of \"%s\" are\n", string);
while (position <= string_length)
{
while (length <= temp)
{
pointer = substring(string, position, length);
printf("%s\n", pointer);
free(pointer);
length++;
}
temp--;
position++;
length = 1;
}
return 0;
}
/* Use substring function given in above c program*/
Output:
Enter a string
coding
Substring of "coding" are
c
co
cod
codi
codin
coding
o
od
odi
odin
oding
d
di
din
ding
i
in
ing
n
ng
g
#include <string.h>
#include <malloc.h>
char* substring(char*, int, int);
main()
{
char string[100], *pointer;
int position = 1, length = 1, temp, string_length;
printf("Enter a string\n");
gets(string);
temp = string_length = strlen(string);
printf("Substring of \"%s\" are\n", string);
while (position <= string_length)
{
while (length <= temp)
{
pointer = substring(string, position, length);
printf("%s\n", pointer);
free(pointer);
length++;
}
temp--;
position++;
length = 1;
}
return 0;
}
/* Use substring function given in above c program*/
Output:
Enter a string
coding
Substring of "coding" are
c
co
cod
codi
codin
coding
o
od
odi
odin
oding
d
di
din
ding
i
in
ing
n
ng
g
0 comments:
Post a Comment