As the title says, I'm searching for a way to ask the user for input again if they dont provide an expected answer. I've searched around for some time, but all I've found was stuff for python and age stuff... I compare strings, couldn't tailor it to what I wanted.
I used goto in C# if the user did not give a wanted input (e.g. "1","2","3","4","debug","test"). Here's an example:
label:
string userinput == Console.ReadLine();
if (userinput == "test")
{
// stuff here
}
else if (userinput == "debug")
{
// more code here
}
else
{
goto label:
}
Here in C:
char userinput[20];
label:
printf("> ");
scanf("%s", userinput);
if (strcmp(userinput,"debug") == 0)
{
// stuff here
}
else if (strcmp(userinput,"test") == 0)
{
// more stuff here
}
else if (strcmp(userinput,"1") == 0)
{
// you get the idea
}
else
{
goto label;
}
I could maybe use goto in C as well, but upon reading more, I see that many are against using goto, so I decided not to, as it was really getting hard to keep up with it as well. How can I loop this? I'm a beginner in C, been thinking about this for a week now. Decided to ask here at last, sorry if this is a duplicate, any help appreciated!