Click here to Skip to main content
15,610,475 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
I just need an idea about how to approach!!!

What I have tried:

I’m having no idea!!
Don’t no how to approach for it and get started!!
Updated 18-Feb-18 21:56pm
Daniel Pfeffer 18-Feb-18 15:16pm    
How would you do this by hand?
For example, take the string "abc". How would you extract all of the substrings? Now do the same for "abcd". Do you see the pattern?

Now write it in code.
PIEBALDconsult 18-Feb-18 16:48pm    
Not enough information.
[no name] 18-Feb-18 18:44pm    
You may know the EXACT requirement. We don't. Give some examples with outputs you expect.
Rick York 19-Feb-18 14:21pm    
The first thing I would do is get an exact definition of the word substring. There are several possibilities and it is not exactly clear which one you want in this case.

How to find all substrings of a given string

With a sheet of paper and a pencil, you get something like:
- imput string= "abcdef"
- substrings: "a" "ab" "abc" "abcd" "abcde" "abcdef" "b" "bc" "bcd" "bcde" "bcdef" "c" "cd" "cde" "cdef" "d" "de" "def" "e" "ef" "f"
- find which operations give the substrings in order and what are the changes between 2 of them.
- deduce the algorithm and write code.

We do not do your HomeWork.
HomeWork is not set to test your skills at begging other people to do your work, it is set to make you think and to help your teacher to check your understanding of the courses you have taken and also the problems you have at applying them.
Any failure of you will help your teacher spot your weaknesses and set remedial actions.
Share this answer
Go recursive.
If you don't know recursion then have a look at Recursion (computer science) - Wikipedia[^].
Share this answer
PIEBALDconsult 18-Feb-18 16:11pm    
CPallini 19-Feb-18 4:43am    
Why not?
PIEBALDconsult 19-Feb-18 8:59am    
A brute force approach would be to use two loops.

outer loop goes from 0 to len-1,
inner loop goes from outer-loop-var to len-1
extract substring using the two loop variables as start and end index (use strncpy)

This should work in any language, and your choice seems to be C.
Share this answer
PIEBALDconsult 18-Feb-18 21:09pm    
inner loop goes from 0 to len-<outer loop variable> ?
inner loop goes from <outer loop variable> to len-1 ?
Nish Nishant 19-Feb-18 10:22am    
Oops, you are right. I'll edit it :-)
Finding substrings in C is the task of the function strok.
As delimiter you should use the space " ".

Some tutorial on strtok. On this site you can also learn the basics of the language C.

Another question is, what you mean with "finding substrings". You can use other strings as delimiter in strtok.
Share this answer
static void Main(string[] args)
    const string word = "abcdef";
    for (int i = 0; i < word.Length; i++)
        Console.WriteLine(word.Substring(0, i + 1));
Share this answer
Nelek 18-Feb-18 16:23pm    
that's not C

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900