how to print a increasing number of words?
im looking for a refrence to learn from and/or help with the algorithm.
i have a homework assignment where i recieve a string and then i have to print a incresaing amount of its words, like this:
input: this is a example
this is a
this is a example
im allowed to loop across the string (which is a max of 100 chars) only once.
my idea is to:
receive the string and save it in a fixed array.
allocate memory and save the string in it.
call a function that replaces ' ' with '/0' .
count how many times '/0' appears (=n).
for (i=0; i<n; i++)
use scanf i times to read the string in to a nulled array-(i dont know how to do this)
print the scaned string.
have you got a easier way to do this or any advice?
thanks a lot,