bool & scanf

Discussion in 'C++' started by howa, Apr 20, 2008.

  1. howa

    howa Guest

    Hi,

    How to accept bool value from stdin, using scanf?

    e.g.

    bool b ;
    scanf_s("%d", &b);

    It will show:

    Unhandled exception at 0x0040a083 in MSFT.exe: 0xC0000005: Access
    violation writing location 0xffffffe4.


    Thanks.
     
    howa, Apr 20, 2008
    #1
    1. Advertising

  2. On 2008-04-20 11:55, howa wrote:
    > Hi,
    >
    > How to accept bool value from stdin, using scanf?
    >
    > e.g.
    >
    > bool b ;
    > scanf_s("%d", &b);
    >
    > It will show:
    >
    > Unhandled exception at 0x0040a083 in MSFT.exe: 0xC0000005: Access
    > violation writing location 0xffffffe4.


    scanf can not read into boolean, you have to read into an int (or
    similar) and then convert the value to bool (or you can read in a string
    and convert the text to bool).

    --
    Erik Wikström
     
    Erik Wikström, Apr 20, 2008
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Weng Tianxiang
    Replies:
    2
    Views:
    496
    Weng Tianxiang
    Jun 21, 2005
  2. Ignacio Machin

    Re: Convert DataRow content to bool

    Ignacio Machin, Jul 7, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    397
    Ignacio Machin
    Jul 7, 2003
  3. Eliyahu Goldin

    Re: Convert DataRow content to bool

    Eliyahu Goldin, Jul 7, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    372
    Eliyahu Goldin
    Jul 7, 2003
  4. =?ISO-8859-1?Q?Martin_J=F8rgensen?=

    scanf (yes/no) - doesn't work + deprecation errors scanf, fopen etc.

    =?ISO-8859-1?Q?Martin_J=F8rgensen?=, Feb 16, 2006, in forum: C Programming
    Replies:
    185
    Views:
    3,524
    those who know me have no need of my name
    Apr 3, 2006
  5. =?ISO-8859-1?Q?Martin_J=F8rgensen?=

    difference between scanf("%i") and scanf("%d") ??? perhaps bug inVS2005?

    =?ISO-8859-1?Q?Martin_J=F8rgensen?=, Apr 26, 2006, in forum: C Programming
    Replies:
    18
    Views:
    709
    Richard Bos
    May 2, 2006
Loading...

Share This Page