--- a/main.rs
+++ b/main.rs
@@ -533,6 +533,7 @@
         let mut left_align = false;
         let mut plus_flag = false;
         let mut zero_pad = false;
+        let mut space_flag = false;
         while i < chars.len() && "#-+ 0".contains(chars[i]) {
             if chars[i] == '-' {
                 left_align = true;
@@ -540,6 +541,8 @@
                 plus_flag = true;
             } else if chars[i] == '0' {
                 zero_pad = true;
+            } else if chars[i] == ' ' {
+                space_flag = true;
             }
             i += 1;
         }
@@ -615,7 +618,7 @@
             },
             'd' | 'i' => {
                 let val = self.getlong();
-                self.print_formatted_long(val, havefieldwidth, fieldwidth, haveprecision, precision, left_align, plus_flag, zero_pad)?;
+                self.print_formatted_long(val, havefieldwidth, fieldwidth, haveprecision, precision, left_align, plus_flag, zero_pad, space_flag)?;
             },
             'o' | 'u' | 'x' | 'X' => {
                 let val = self.getulong();
@@ -668,8 +671,8 @@
         Ok(())
     }
 
-    fn print_formatted_long(&self, val: i64, havefieldwidth: bool, fieldwidth: i32, haveprecision: bool, precision: i32, left_align: bool, plus_flag: bool, zero_pad: bool) -> Result<(), String> {
-        if plus_flag && val >= 0 {
+    fn print_formatted_long(&self, val: i64, havefieldwidth: bool, fieldwidth: i32, haveprecision: bool, precision: i32, left_align: bool, plus_flag: bool, zero_pad: bool, space_flag: bool) -> Result<(), String> {
+        if plus_flag && val >= 0 {
             if havefieldwidth && haveprecision {
-                print!("+{:0width$.prec$}", val, width = (fieldwidth.max(0) as usize).saturating_sub(1), prec = precision.max(0) as usize);
+                print!("+{:width$.prec$}", val, width = (fieldwidth.max(0) as usize).saturating_sub(1), prec = precision.max(0) as usize);
             } else if havefieldwidth {
                 if left_align {
@@ -683,8 +686,27 @@
             } else {
                 print!("+{}", val);
             }
+        } else if space_flag && val >= 0 {
+            if havefieldwidth && haveprecision {
+                print!(" {:width$.prec$}", val, width = (fieldwidth.max(0) as usize).saturating_sub(1), prec = precision.max(0) as usize);
+            } else if havefieldwidth {
+                if left_align {
+                    print!(" {:<width$}", val, width = (fieldwidth.max(0) as usize).saturating_sub(1));
+                } else if zero_pad {
+                    print!(" {:0width$}", val, width = (fieldwidth.max(0) as usize).saturating_sub(1));
+                } else {
+                    print!(" {:width$}", val, width = (fieldwidth.max(0) as usize).saturating_sub(1));
+                }
+            } else if haveprecision {
+                print!(" {:0.prec$}", val, prec = precision.max(0) as usize);
+            } else {
+                print!(" {}", val);
+            }
         } else {
             if havefieldwidth && haveprecision {
-                print!("{:0width$.prec$}", val, width = fieldwidth.max(0) as usize, prec = precision.max(0) as usize);
+                print!("{:width$.prec$}", val, width = fieldwidth.max(0) as usize, prec = precision.max(0) as usize);
             } else if havefieldwidth {
                 if left_align {
                     print!("{:<width$}", val, width = fieldwidth.max(0) as usize);
