doubt

57 views
Skip to first unread message

subbu raj

unread,
Jul 22, 2020, 3:06:35 PM7/22/20
to Discussion forum for Introduction to Programming in C
if a program has scanf("%d",&a) when i give character input why cant it take the asccii value of the character which is an int and store it in a instead showing error eg if i give input as A its ascii value 65 can be stored in a why there is an error

NOC20 CS91

unread,
Aug 3, 2020, 1:54:38 PM8/3/20
to Discussion forum for Introduction to Programming in C
Hi,
Because you are using %d in scanf which expects an integer value as input. If you are interested in ASCII value of character. Use the below code:

int main()
{
    int a;
    scanf("%c",&a);
    printf("%d",a);

    return 0;
}

Thanks
Prateek
Reply all
Reply to author
Forward
0 new messages