-
Notifications
You must be signed in to change notification settings - Fork 372
Expand file tree
/
Copy pathsubstring.c
More file actions
31 lines (29 loc) · 768 Bytes
/
substring.c
File metadata and controls
31 lines (29 loc) · 768 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
// C program to print all possible substrings of a given string
#include<stdio.h>
#include<string.h>
// Function to print all sub strings
void subString(char str[], int n)
{
// Pick starting point
for (int len = 1; len <= n; len++)
{
// Pick ending point
for (int i = 0; i <= n - len; i++)
{
// Print characters from current
// starting point to current ending
// point.
int j = i + len - 1;
for (int k = i; k <= j; k++)
printf("%c",str[k]);
printf("\n");
}
}
}
// Driver program to test above function
int main()
{
char str[] = "abcdef";
subString(str, strlen(str));
return 0;
}