Pure Programmer
Blue Matrix


Cluster Map

Project: Aligning Integers with printf()

Write a program that demonstrates left-padding, right-padding and zero-padding using format() and sprintf() style formatting. Use the vertical bar character before and after the format specifier so that you can see where the output begins and ends. Use printf() to print the 32-bit integers and sprintf() to print the 64-bit integers. Print the values in both decimal and hexadecimal. Your program should reproduce the output shown using the following variables:

  • a32 = 106276
  • b32 = -2147483648
  • c32 = 4080400
  • a64 = 11294588176
  • b64 = -4294967296
  • c64 = 9223372036854775807

Output
$ rustc AligningIntegersWithPrintf.rs error[E0425]: cannot find function `printf` in this scope --> AligningIntegersWithPrintf.rs:15:2 | 15 | printf("|%11d|%9x|\n",a32,a32); | ^^^^^^ not found in this scope | help: you may have meant to use the `print` macro | 15 | print!("|%11d|%9x|\n",a32,a32); | ~~~~~~ error[E0425]: cannot find function `printf` in this scope --> AligningIntegersWithPrintf.rs:16:2 | 16 | printf("|%-11d|%-9x|\n",a32,a32); | ^^^^^^ not found in this scope | help: you may have meant to use the `print` macro | 16 | print!("|%-11d|%-9x|\n",a32,a32); | ~~~~~~ error[E0425]: cannot find function `printf` in this scope --> AligningIntegersWithPrintf.rs:17:2 | 17 | printf("|%011d|%09x|\n",a32,a32); | ^^^^^^ not found in this scope | help: you may have meant to use the `print` macro | 17 | print!("|%011d|%09x|\n",a32,a32); | ~~~~~~ error[E0425]: cannot find function `printf` in this scope --> AligningIntegersWithPrintf.rs:18:2 | 18 | printf("|%11d|%9x|\n",b32,b32); | ^^^^^^ not found in this scope | help: you may have meant to use the `print` macro | 18 | print!("|%11d|%9x|\n",b32,b32); | ~~~~~~ error[E0425]: cannot find function `printf` in this scope --> AligningIntegersWithPrintf.rs:19:2 | 19 | printf("|%-11d|%-9x|\n",b32,b32); | ^^^^^^ not found in this scope | help: you may have meant to use the `print` macro | 19 | print!("|%-11d|%-9x|\n",b32,b32); | ~~~~~~ error[E0425]: cannot find function `printf` in this scope --> AligningIntegersWithPrintf.rs:20:2 | 20 | printf("|%011d|%09x|\n",b32,b32); | ^^^^^^ not found in this scope | help: you may have meant to use the `print` macro | 20 | print!("|%011d|%09x|\n",b32,b32); | ~~~~~~ error[E0425]: cannot find function `printf` in this scope --> AligningIntegersWithPrintf.rs:21:2 | 21 | printf("|%11d|%9x|\n",c32,c32); | ^^^^^^ not found in this scope | help: you may have meant to use the `print` macro | 21 | print!("|%11d|%9x|\n",c32,c32); | ~~~~~~ error[E0425]: cannot find function `printf` in this scope --> AligningIntegersWithPrintf.rs:22:2 | 22 | printf("|%-11d|%-9x|\n",c32,c32); | ^^^^^^ not found in this scope | help: you may have meant to use the `print` macro | 22 | print!("|%-11d|%-9x|\n",c32,c32); | ~~~~~~ error[E0425]: cannot find function `printf` in this scope --> AligningIntegersWithPrintf.rs:23:2 | 23 | printf("|%011d|%09x|\n",c32,c32); | ^^^^^^ not found in this scope | help: you may have meant to use the `print` macro | 23 | print!("|%011d|%09x|\n",c32,c32); | ~~~~~~ error[E0425]: cannot find function `sprintf` in this scope --> AligningIntegersWithPrintf.rs:24:17 | 24 | println!("{}", sprintf("|%20ld|%17lx|",a64,a64)); | ^^^^^^^ not found in this scope error[E0425]: cannot find function `sprintf` in this scope --> AligningIntegersWithPrintf.rs:25:17 | 25 | println!("{}", sprintf("|%-20ld|%-17lx|",a64,a64)); | ^^^^^^^ not found in this scope error[E0425]: cannot find function `sprintf` in this scope --> AligningIntegersWithPrintf.rs:26:17 | 26 | println!("{}", sprintf("|%020ld|%017lx|",a64,a64)); | ^^^^^^^ not found in this scope error[E0425]: cannot find function `sprintf` in this scope --> AligningIntegersWithPrintf.rs:27:17 | 27 | println!("{}", sprintf("|%20ld|%17lx|",b64,b64)); | ^^^^^^^ not found in this scope error[E0425]: cannot find function `sprintf` in this scope --> AligningIntegersWithPrintf.rs:28:17 | 28 | println!("{}", sprintf("|%-20ld|%-17lx|",b64,b64)); | ^^^^^^^ not found in this scope error[E0425]: cannot find function `sprintf` in this scope --> AligningIntegersWithPrintf.rs:29:17 | 29 | println!("{}", sprintf("|%020ld|%017lx|",b64,b64)); | ^^^^^^^ not found in this scope error[E0425]: cannot find function `sprintf` in this scope --> AligningIntegersWithPrintf.rs:30:17 | 30 | println!("{}", sprintf("|%20ld|%17lx|",c64,c64)); | ^^^^^^^ not found in this scope error[E0425]: cannot find function `sprintf` in this scope --> AligningIntegersWithPrintf.rs:31:17 | 31 | println!("{}", sprintf("|%-20ld|%-17lx|",c64,c64)); | ^^^^^^^ not found in this scope error[E0425]: cannot find function `sprintf` in this scope --> AligningIntegersWithPrintf.rs:32:17 | 32 | println!("{}", sprintf("|%020ld|%017lx|",c64,c64)); | ^^^^^^^ not found in this scope error: aborting due to 18 previous errors For more information about this error, try `rustc --explain E0425`.

Solution