mirror of
				https://codeberg.org/ziglings/exercises.git
				synced 2025-11-04 04:35:38 +00:00 
			
		
		
		
	
		
			
				
	
	
		
			30 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			Diff
		
	
	
	
	
	
			
		
		
	
	
			30 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			Diff
		
	
	
	
	
	
--- exercises/106_files.zig	2025-03-13 15:26:59.532367792 +0200
 | 
						|
+++ answers/106_files.zig	2025-03-14 22:04:52.243435159 +0200
 | 
						|
@@ -35,7 +35,7 @@
 | 
						|
         // by doing nothing
 | 
						|
         //
 | 
						|
         // we want to catch error.PathAlreadyExists and do nothing
 | 
						|
-        ??? => {},
 | 
						|
+        error.PathAlreadyExists => {},
 | 
						|
         // if there's any other unexpected error we just propagate it through
 | 
						|
         else => return e,
 | 
						|
     };
 | 
						|
@@ -44,7 +44,7 @@
 | 
						|
     // wait a minute...
 | 
						|
     // opening a directory might fail!
 | 
						|
     // what should we do here?
 | 
						|
-    var output_dir: std.fs.Dir = cwd.openDir("output", .{});
 | 
						|
+    var output_dir: std.fs.Dir = try cwd.openDir("output", .{});
 | 
						|
     defer output_dir.close();
 | 
						|
 
 | 
						|
     // we try to open the file `zigling.txt`,
 | 
						|
@@ -55,7 +55,7 @@
 | 
						|
     // but here we are not yet done writing to the file
 | 
						|
     // if only there were a keyword in Zig that
 | 
						|
     // allowed you to "defer" code execution to the end of the scope...
 | 
						|
-    file.close();
 | 
						|
+    defer file.close();
 | 
						|
 
 | 
						|
     // you are not allowed to move these two lines above the file closing line!
 | 
						|
     const byte_written = try file.write("It's zigling time!");
 |