does a a little mess with the buffers.
While looping in the do statement, buffer is made pointing to a buffer that is enlarged as characters are read.
After exiting the loop, the *(buffer++)='\0' statement in fact shift the buffer pointer by one after placing a '\0' thus giving
The proper statement should have probably been
But beware that your call to
, otherwise you will have no space to store the '\0' character at end.
At this point, by returning
, you give the caller the responsibility to free what have been allocated.
You have to call
before loping back to a new
, and before returning from
cmd = getcommand();
if (cmd == 'q')
printf("exit character has been detected\n");
printf("the command is %s\n",cmd);