I wanna reproduce the terminal behavior when the input is just a new line (keeps printing the same string), but don't know how to do it.
Example: When the user just inputs a new line, the terminal keeps printing the directory, until a real command is inserted
int main()
{
char userInput[1024];
while (1)
{
printf("directory »» ");
scanf("%[^\n]" , userInput); // This scanf doesn't work
while (userInput[0] == '\n') // If the input is only a new line char, keep asking for more inputs and printing the directory
{
printf("directory »» ");
scanf(" %[^\n ]" , userInput); // This scanf doesn't work
}
//Input isn't a NewLine, process the input
process_Input_Function(userInput); //Isn't empty, search for my created commands
}
}
At the first enter
press, it enters the loop, reproduce 1 time, and then the scanf
doesn't detect new lines anymore, it just skips and waits to a real string.
What can i type inside of the scanf
to detect a new line input and keep printing that string till a real command is inserted?
I tried with scanf("%c"...)
but the problem with a char, is that i can't process the whole string command, if isn't empty