#include <stdio.h> //for printf
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
//#define STDOUT_FILENO 1
// define STDERR_FILENO 2
int main(){
// mode_t mode = S_IROTH | S_IRUSR | S_IWUSR;
mode_t mode = S_IRUSR | S_IWUSR;
close(1);
int fildes = open("hello_world.txt", O_CREAT | O_TRUNC | O_RDWR, mode);
printf("Hi! My Name is \n" );
close(fildes);
return 0;
}
From what I learned, "Hi! My Name is" should be printed to "hello_world.txt". It works well in Linux virtual machine which my professor provided. But in my machine (I'm using remote WSL in vscode), "hello_world.txt" is empty. Can I fix this problem?