Filter input to only numbers in C

How to receive input from user, only numbers?
this is my code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#include <windows.h>
#include <stdio.h>

int a;
int b;
int options;

void premenu()
{
    printf("\n\t\t* Operatori Unari - Increment si Decrement *\n\n");
    printf("\n\tIntroduceti a = ");
    scanf("%d", &a);
}
void menu()
{
    printf("\n\tAlege una din optiunile de mai jos:\n"
           "\n 1. Post Incrementare (b = a++)"
           "\n 2. Pre Incrementare (b = ++a)"
           "\n 3. Post Decrementare (b = a--)"
           "\n 4. Pre Decrementare (b = --a)"
           "\n 5. Iesire Program"
           "\n\n Selectati: ");
    scanf("%d", &options);
}
int main()
{
    premenu();
    menu();
    int i;
    for(i = 0; i < options;)
    {
        if(options == 1)
        {
            b = a++;
            printf("\n a = %d si b = %d\n", a, b);
            Sleep(2500);
            system("cls");
            premenu();
            menu();
        }
        else if(options == 2)
        {
            b = ++a;
            printf("\n a = %d si b = %d\n", a, b);
            Sleep(2500);
            system("cls");
            premenu();
            menu();
        }
        else if(options == 3)
        {
            b = a--;
            printf("\n a = %d si b = %d\n", a, b);
            Sleep(2500);
            system("cls");
            premenu();
            menu();
        }
        else if(options == 4)
        {
            b = --a;
            printf("\n a = %d si b = %d\n", a, b);
            Sleep(2500);
            system("cls");
            premenu();
            menu();
        }
        else if(options == 5)
        {
            Sleep(1000);
            system("cls");
            printf("\n\n\tTerminare Program ! Apasati orice tasta pentru a inchide.\n");
            Sleep(3000);
            system("cls");
            break;
        }
        else
        {
            printf("\n Nu exista aceasta optiune !\n");
            Sleep(1000);
            printf("\n Selectati 1, 2, 3, 4 sau 5");
            Sleep(2500);
            system("cls");
            printf("\n\t\t* Operatori Unari - Increment si Decrement *\n\n");
            printf("\n\tIntroduceti a = %d\n", a);
            menu();
        }
    }
    return 0;
}


Sorry for the language in the code not english tho.. :\
Last edited on
Thank you Manga .. this was very helpful !! :)
Topic archived. No new replies allowed.