If i were you,i would keep scanf on play.However you should eat all the whitespaces(you can extend it to eating tabs as well).So,read the input ,eat whitespaces and enter's and then check if it is an int or not.
Code:
#include <stdio.h>
#include <stdlib.h>
/* TODO: Fazer a validação para quando o usuário digita um espaço,
* pois está dando um resultado inesperado, como se um <Enter> estivesse
* sendo pressionado. */
/* TODO: Problem when the user <enters> a space and then <Enter> */
#define TRUEINT 1
void clear_screen ( void );
int main ( void ) {
int iNum1 = 0;
int iNum2 = 0;
int c;
clear_screen();
printf("A program that asks for two numbers and show them.\n\n");
/* First integer. */
printf("Enter an -integer-: ");
do//check for whitespaces
{
c = getchar();//grab the first character of the input
if( c == '\n')//we reached the end of input and no number was found
printf("Please insert an integer\n");//so print message
}while( c == ' ' || c == '\n');//if it enter or whitespace,eat them
ungetc(c,stdin);//something we need to read so put back in stream stdin
while (scanf("%d", &iNum1) != TRUEINT) {
while ( getchar() != '\n' ); // Limpa o buffer.
printf("Not an integer: ");
}
c = getchar();//eat the '\n' from the first input
/* Second integer. */
printf("Enter the second -integer-: ");
do
{
c = getchar();
if( c == '\n')//we reached the end of input and no number was found
printf("Please insert an integer\n");
}while( c == ' ' || c == '\n');
ungetc(c,stdin);
while (scanf("%d", &iNum2) != TRUEINT) {
while ( getchar() != '\n' ); // Limpa o buffer.
printf("Not an integer: ");
}
printf("\t%d, %d\n", iNum1, iNum2);
return EXIT_SUCCESS;//why not use return 0; instead?
}
void clear_screen(void) {
if (system("clear")) system("cls");
}
If you have any questions,please ask me