Error with file I/O system tasks($feof,$fscanf)

module break_continue;

initial
begin
bit [1024:0] cmd;
int x;
int c;

x = $fopen("test.txt");
$display("x=%d",x);

while(!($feof ( x )))
begin

c=$fscanf(x,"%s",cmd);
$display("cmd=%s",cmd);
 case(cmd)
" " : continue;
"done": break;
endcase
end
$fclose(x);
end
endmodule

In above code at simulation below errors are coming, please help

$feof : Argument 1 is not a valid file descriptor.
$fscanf : Argument 1 is not a valid file descriptor.

In reply to DVEngineer:

Do you know if the file opened successfully? Use $ferror to find out.

In reply to dave_59:

The file is successfully opening.

x value printing as 2.

In reply to DVEngineer:

module break_continue;
initial
begin
bit [1024:0] cmd;
int x;
int c;
x = $fopen("test.txt");
$display("x=%d",x);
while(!($feof ( x )))
begin
c=$fscanf(x,"%s",cmd);
$display("cmd=%s",cmd);
case(cmd)
" " : continue;
"done": break;
endcase
end
$fclose(x);
end
endmodule

In above code at simulation below errors are coming, please help
$feof : Argument 1 is not a valid file descriptor.
$fscanf : Argument 1 is not a valid file descriptor.

x = $fopen(“test.txt”,“r”); //specify mode while opening file.

In reply to Er. Shipra:

Thank you