#include <stdio.h> #include <string.h> void print_substring (char const * from, char const * to) { // One could check return value to ensure // that all characters have been written, // but then you also need to decide what // to do in the case of an error. } void print_all_substrings(char const * string) { for (size_t substring_length = 1; substring_length <= string_length; ++substring_length) { char const * const last_begin = string + (string_length - substring_length); char const * begin = string; for (; begin != last_begin; ++begin) { print_substring(begin, begin + substring_length); } print_substring(last_begin, last_begin + substring_length); } } int main () { }
Standard input is empty
a, b, c, d, e, f, g ab, bc, cd, de, ef, fg abc, bcd, cde, def, efg abcd, bcde, cdef, defg abcde, bcdef, cdefg abcdef, bcdefg abcdefg -- a -- --