while (fgets(buffer, sizeof buffer, stdin) == NULL || sscanf(buffer, "%d %d %d %d %d", &layerCount, &topLayerHeight, &layerHeightGrowth, &trunkWidth, &trunkHeight) != 5)
{
printf("Invalid input. Reinput all 5 values.\n");
}
Why does this piece of code freeze when i input "1 2 3 4 ^Z"? fgets should read "1 2 3 4 " and then sscanf would fail, and thus printing "Invalid input. Reinput all 5 values.\n"