This question already has an answer here:
- Reading string from input with space character? [duplicate] 14 answers
I want the following to ask for input and then take in a string (with spaces), then do it again. But it repeatedly outputs "input$" after typing in the first string.
char command[80];
while(1)
{
printf("input$ ");
scanf("%[^\n]", command);
}
My output: nput$ input$ input$ input$ input$ input$ input$ input$ input$ input$ input$ input$ input$ input$ input$ input$ input$ input$ input$ input$ input$ input$ input$ input$ input$ input$ input$ input$ input$ input$ input$ input$ input$ input$ input$ input$ input$ input$ input$ input$ input$ input$ input$ input$ input$ input$ input$ input$ input$ input$ input$ input$ input$ input$ input$^C
What I want:
input$ hi
input$ this can take spaces
input$