Program to print all substrings of a given string | C ++ program to print all possible substrings of a given string ; Function to print all sub strings ; Pick starting point ; Pick ending point ; Print characters from current starting point to current ending point . ; Driver program to test above function
#include <bits/stdc++.h> NEW_LINE using namespace std ; void subString ( char str [ ] , int n ) { for ( int len = 1 ; len <= n ; len ++ ) { for ( int i = 0 ; i <= n - len ; i ++ ) { int j = i + len - 1 ; for ( int k = i ; k <= j ; k ++ ) cout << str [ k ] ; cout << endl ; } } } int main ( ) { char str [ ] = " abc " ; subString ( str , strlen ( str ) ) ; return 0 ; }