how to test input type in c programming


This Content is from Stack Overflow. Question asked by yuchen liu

the purpose is to verify the user input, and sent error message if they enter integer when I asking for string, or enter string when I asking for integer, or any other weird symbol etc.

could anyone get me a full version of the example to demonstrate how to test for:

1.test for float type ( input )
2.test for string type ( input )
3.test for character type ( input )

and under below is my code for testing integer:

int getAge(){
    int x;
    puts("please enter your age:nn");
    x = scanf("%d",&age);
    if (x == 1){
        printf("You have entered :%d",age);
        return (age);
    else {


This question is not yet answered, be the first one who answer using the comment. Later the confirmed answer will be published as the solution.

This Question and Answer are collected from stackoverflow and tested by JTuto community, is licensed under the terms of CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.

people found this article helpful. What about you?