I have made a c code intended to create a file at root directory.
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
const char *path="/";
int main(){
FILE *fp;
umask(0);
chdir(path);
fp=fopen("test.txt","w+");
fclose(fp);
return 0;
}
the compilation gives no errors but when I execute the file, the following error appears:
kwagjj@kwagjj-Inspiron-3420:~$ gcc -Wall a2.c -o a2
kwagjj@kwagjj-Inspiron-3420:~$ ./a2
Segmentation fault (core dumped)
how am I using the umask
function wrong?