Subj : Re: sscanf and bool To : borland.public.cpp.borlandcpp From : Jogy Date : Tue Aug 24 2004 11:18 am MarvinAvery wrote: > Hi. > > I am using BC5.02 under Win2K. > > I have a character string that contains some boolean values: eg. "0010" > I want to read these values via the sscanf() function: eg. > bool b1, b2, b3, b4; > sscanf (line, "%1d%1d%1d%1d", &b1, &b2, &b3, &b4); > > Problem is "%1d" stores the value as int -- that is as 16 bits whereas the > storage location is only 8 bits. So I am getting a buffer overflow. > > Is there any conversion format that will read and store an 8-bit integer? > Any other suggestions? > > TIA > Hello, I think %c is the printf/scanf format for 8-bit variable. But I am not sure if the current C++ standard specifies that the size of bool is 8-bit ..... It may be safer to scanf into integer variables and then convert them to bool. Jogy .