Error reading char in read

Ali Çehreli via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Feb 17 12:24:11 PST 2017


On 02/17/2017 12:05 PM, wiki wrote:

 > So I executed it here anyway but still it presents arbitrary characters
 > in the char ..

Right. char[50] is not suitable for user interaction like that. Use 
string, char[], etc.

 > What I thought was to create a reader where I could receive,
 > Char, string, int, float, double, real, for my future codes ....

That's already available in many different ways: readf, readln, 
formattedRead, etc.

 > I tried doing this to understand how the char reading was, it is
 > preferable to use strings but the language has some specific reader for
 > char?

"%c" can be used to read char. (Although, I still think you want to read 
a string, not a single char.)

import std.stdio;

void main() {
     char c;
     readf("%c", &c);
}

 > minha frase na captura de char ������������������������

Sorry, Google Translate did not work for that one. :(

There is a confusion here. You keep saying 'char' but � is not a char 
(i.e. one of the 8-bit types). It's the Unicode character "U+FFFD 
REPLACEMENT CHARACTER", which is represented by 2 chars in D. char is a 
UTF-8 code unit, not a "character" in the sense that I think you're 
using it.

Ali



More information about the Digitalmars-d-learn mailing list