bool & scanf

H

howa

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.
 
E

Erik Wikström

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).
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top