Skip to content

added substring.c #292

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ These program are written in codeblocks ide for windows. These programs are not
- [To check if a matrix is a sparse matrix or not](https://github.com/gouravthakur39/beginners-C-program-examples/blob/master/SparseMatrix_017.c)
- [To calculate the Least Common Multiple](https://github.com/gouravthakur39/beginners-C-program-examples/blob/master/lcm.c)
- [Lambda in C](https://github.com/gouravthakur39/beginners-C-program-examples/blob/master/lambda_in_c.c)
- [All substrings of a string](https://github.com/gouravthakur39/beginners-C-program-examples/blob/master/substring.c)
# Contributing
This is a personal learning project for me.

Expand Down
31 changes: 31 additions & 0 deletions substring.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,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;
}