473,320 Members | 2,048 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

bool & scanf

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.
Jun 27 '08 #1
1 24033
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
Jun 27 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
by: Peter Mount | last post by:
Hello I'm having trouble with " scanf("%c", &answer);" on line 20 below. When I run the program in cygwin on Windows 98SE it skips that line completely and ends the program. Does scanf have...
4
by: sushant | last post by:
hi why do we use '&' operator in scanf like scanf("%d", &x); but why not in printf() like printf("%d" , x); thnx in advance sushant
13
by: Betaver | last post by:
What char represent "a new line"?13 or 10, or both? I got a lot of problem when read a char. Eg. ======== 1 2 a b ======== If I write: int n1,n2; char c1,c2;
30
by: James Daughtry | last post by:
char array; scanf("%19s", &array); I know this is wrong because it's a type mismatch, where scanf expects a pointer to char and gets a pointer to an array of 20 char. I know that question 6.12...
0
by: sala | last post by:
this is my programm, there is a mistake because it doesn't give the right answer; the quetion is below the program: #include<stdio.h> #define maxsize 100 void fillarray(double*, int); void...
7
by: Army1987 | last post by:
Is this OK? If not, why? #include <stdio.h> #include <stdlib.h> #include <string.h> #define MAXLEN 32767 #define DIGITS 5 /* number of decimal digits in MAXLEN */ int main(void) { size_t i;
2
by: sophia | last post by:
why scanf("%d. %d. %d",&d,&m,&y); is NOT reading the i/p 22 4 1972 correctly, whereas it is reading the i/p 22. 4. 1972 correctly ?. Is it because of the dot in the format string of scanf ?
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.