You have some considered responses from experienced people.
If you read this
http://www.cplusplus.com/reference/cstdio/fgets/[
^] you may understand why the comments were made.
At the moment in your code
user_input
points into space. You need to allocate some memory to it before you use it with
fgets()
The fact that you get something to happen at the moment is just coincidence. That bug needs to be fixed first.
You haven't said which compiler and OS you are using which will affect your results.
A few comments explaining what your code is meant to do would also be a good idea.
I would suggest these changes:
char user_input[INPUT_SIZE ];
char *cur_token=NULL;
Change this function:
char * getInput(char *user_input){
printf(">>: ");
return fgets(user_input,INPUT_SIZE,stdin);
}
And add this:
if(NULL ==getInput(user_input))
{
printf("Input error occured.\n");
break;
}
At the moment FLUSH_STDIN can never be called (even before you make any changes):
if (!(len < (INPUT_SIZE-1)))
FLUSH_STDIN(user_input);
Why have you used a macro for FLUSH_STDIN(x) and not a function?
http://stackoverflow.com/questions/14041453/why-are-preprocessor-macros-evil-and-what-are-the-alternatives[
^]
Because your application is running in a console you have access to command line history. The up and down arrows are used to view this. This behaviour can be modified:
http://msdn.microsoft.com/en-us/library/ms686031%28v=VS.85%29.aspx[
^]
http://msdn.microsoft.com/en-us/library/ms682077%28v=VS.85%29.aspx[
^]
In Windows 7 if you press F7 you will see the entire history.
http://en.kioskea.net/faq/14204-windows-7-view-the-command-prompt-history[
^]
alt-F7 will clear the history. You may also change the default settings manually. Click the console's control box (top left), properties, options tab: "Command history." The default is 50 items, 4 buffers.