June 2021
Beginner
344 pages
8h 9m
English
The program’s output looks good on screen, but it contains a subtle bug. The string contains some extra characters representing the ENTER key. You can see this by replacing your last println! call with the following:
| | println!("{:?}", name); |
Replacing the {} placeholder with {:?} uses the debug placeholder. Any type that supports debug printing will print a detailed debugging dump of its contents, rather than just the value. If you run the program now, you can see the problem:
| <= | Hello, what's your name? |
| => | Herbert |
| <= | "Herbert\r\n" (or "Herbert\n" on UNIX-based systems) |
\r is a special character that means carriage return. On old printers, it returned the printhead ...
Read now
Unlock full access