FileNotFound with Zig run and Format Specifier Error

I am getting the error written below.
C:\Windows\system32>zig run main.zig
C:\zig\lib\std\std.zig:200:22: error: unable to load ‘main.zig’: FileNotFound
const root = @import(“root”);

Why does not work?

Hey @ahmet111

FileNotFound is an error you’ll get if you don’t specify the correct path. Make sure that:

  1. The main.zig file exists
  2. The “zig run” command is directed at that file.

For instance, if you have main.zig in your Documents folder, make sure that you are running it against that proper address.

The file named main.zig is in the zig folder in c.

If your running zig from this directory then main.zig would need to be at

C:\Windows\system32\main.zig

If you’re saying the main.zig file is located at

C:\zig\main.zig

Then you would need to run it from that directory or provide it with the absolute path:

zig run C:\zig\main.zig

If you provide a relative path then zig is looking relative to the current working directory, not from your zig installation

My file named main.zig is located in the zig folder in c. I did as you said. it didn’t work again.

C:\Windows\system32>zig run C:\zig\main.zig
C:\zig\lib\std\fmt.zig:604:25: error: cannot format array ref without a specifier (i.e. {s} or {})
@compileError("cannot format array ref without a specifier (i.e. {s} or {
})");
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
referenced by:
format__anon_3763: C:\zig\lib\std\fmt.zig:184:23
print__anon_3577: C:\zig\lib\std\io\writer.zig:28:34
remaining reference traces hidden; use ‘-freference-trace’ to see all reference traces

You’re now getting a different error - you were getting a FileNotFound and now it’s telling you you that you don’t have a format specifier.

In other words, you are now finding the file - now you need to fix the bug in the code.

Can you post your code here?

const std = @import("std");

pub fn main() void {
    const message = "Hello, World!";
    std.debug.print("{}\n", .{message});
}
const std = @import(“std”);

pub fn main() void {
const message = “Hello, World!”;
std.debug.print(“{s}\n”, .{message});
}

you just needed the format specifier {s}

Why do I need this token? what does it do?

You’re telling the machine how to print the array.

In Zig, we don’t have char data types. Instead we use integers. If you want to print something like “abc”, you need to specify that you want to interpret the integers like they are characters.

u8 is just an unsigned integer (typically a byte). If you don’t specify that you intend to read them like characters, it’ll just print numbers on the screen. There’s more to it than that, but you can read up on that in the fmt library and in the documentation.

Thank you.
The people whose lectures I watched and read left this blank. Why didn’t they mention this?

1 Like

I’m sorry, my friend, I don’t know why they did that. I’m glad we could help you today though :slight_smile:

Always feel free to ask questions.