it doesnt stop for scanf it leaves the old values and enters to an endless loop
That's because you don't clear the stream of any errors and then discard the bad input. Naturally scanf() will fail again on the same bad input if you don't get rid of it first:
Code:
while(numH>=20||numW>=20||numP>=10||numH<=0||numW<=0||numP<=0){
clearerr(stdin);
while ((c = getchar()) != EOF && c != '\n')
;
printf("Incorrect input ,try again\n");
printf("\nEnter puzzle height( < 20 ) width( < 20 ) number of pieces( <= 10 )\n");
scanf("%d %d %d",&numH,&numW,&numP);
}
It behaves strange when I put \n als last char in the format-string.
So don't do that. A lot of people get confused with how scanf() deals with whitespace in the format string.