Mostly like this:
if (fgets(buf, sizeof buf, stdin)) {
} else {
}
You may have difficulty if you press Ctrl + Z in the middle of the line, but start with the main one.
Change after upgrade OP
You have
scanf("%lf", &var);
scanfreturns the number of appointments he made. In your case, you only have one variable, so it scanfreturns 1 in the normal case or 0 when it fails. Just check the return value
int n = scanf("%lf", &var);
if (n != 1)
{
break;
}
PS: ... "% lf" scanf double, var float.