Question: anyone knows an efficient way to check out the format of an scanf'ed data?

e.g. if I try to read an integer and I type a character, how would you do to tell the program that is not correct?

Answer: 
You can check if `scanf()` succeeds, it returns the number of successful conversions it performed.

You should *always* check this, before relying on the result since if it failed the variable(s) might contain undefined data leading to undefined results if referenced.

You can use `if` to check, and re-try with a different conversion specifier on failure:

```
if(scanf("%d", &x) == 1)
  printf("got integer %d\n", x);
else if(scanf("%c", &y) == 1)
  printf("got character '%c'\n", y);
else /* more attempts */

```

Of course it can become troublesome if there are "sub-matches", so the order can matter. It's also *way* better to split the input processing into two steps for the above:

1. Read a full line of input using `fgets()`
2. Use `sscanf()` to parse the line

That way you avoid problems due to the input being streamed in:

```
char line[128];

if(fgets(line, sizeof line, stdin) != NULL)
{
  int x;
  char y;

  if(sscanf(line, "%d", &x) == 1)
    printf("got integer %d\n", x);
  else if(sscanf(line, "%c", &y) == 1)
    printf("got character '%c'\n", y);
}

```

Note that if you wanted to scan for both an integer and a float, it can still become troublesome since a typical float (such as `"3.1416"`) begins with what is a legal integer. For those cases you can use the `strtoXXX()` family of functions, which let you check the remainder after doing the conversion.
As you have mentioned in the question that you are playing with numbers and chars only there is a very simple solution as follows

```
//while reading a char
scanf("%c",&temp);
if(!((temp >=  65 && temp <= 90) || (temp >= 97 && temp <= 122)))
printf("Only characters are allowed!\n");

```

hope this helps!