Does rust have printf or scanf function

Does rust have printf or scanf function so we can specify the %4d or %5.4f (to format the text) and do like:

int main(void){
char c='d';
printf("%d",c);
}
which would print the char as the ASCII value

scanf is bad and you should never use it in any language, but C's printf is functionally the same as Rust's print! macro (though with a different syntax), which uses the same format as format! that is explained here.

2 Likes
fn main() {
   let c = 'd';
   println!("{}", c);
}

Instead of scanf you can use .parse() method. If you need to parse something more complicated, you'll need a regex or a proper parser.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.