%u puts raw unformatted binary data into the file. Do not expected it to be in readable format. Ensure that you are opening the file in binary format "rb" or "wb" ... .Try reading back the binary data and that should show the written value.
You can use %z if you want to save 4 state values.
int rd;
int file = $fopen(path,"wb"); // open in binary mode
if (!file) begin
$error("File could not be open: ", path);
return;
end
$fwrite(file, "%u", 32'h4D424D42);
$fclose(file);
// read back binary data from file
file = $fopen (path,"rb"); // open in binary mode
if (!file) begin
$error("File could not be open: ", path);
return;
end
$fscanf(file,"%u",rd);
$fclose(file);
$display("%h",rd);