I got it! Sort of. So the code below does this now:
Hello world
Hello
world
Which is exactly what I want the program to do but not the way it currently does it.
Code:
#include <stdio.h>
#include <string.h>
#define MAXLENGTH 256
char *next_word(char *instring, char **new_start);
int main()
{
char instring[MAXLENGTH];
char *words=NULL;
char *parsed=NULL;
printf("Enter the freaking text:\n");
fgets(instring, MAXLENGTH, stdin);
puts(instring);
words=next_word(instring, &parsed);
while (words != NULL)
{
printf("%s\n", words);
words=next_word(parsed, &parsed);
}
}
char *next_word(char *instring, char **new_start)
{
new_start=strtok(instring, " ");
//return instring;
}
If I uncomment "return instring" ill only get the first word outputted. Is there a way to make the function return NULL & instring?