Can I write code like this? A novice in C language

What is the standard of practice?

Will this overflow memory?

I want to get a FileDescriptor.

int fd = fileno(fopen("/path", "w+"));
close(fd);

//or

FILE * fp = fopen("...");
int fd = fileno(fd);

fclose(fp);

For some reason, I have to use "fopen"


The standard way of doing this is to use matching open and close functions. This is true of files and memory and anything else that gives you a magic value/pointer/whatever.

Hence, use fopen() with fclose(). Use open() with close(). Use malloc() with free(). Etc.

If you need to access the underlying file descriptor / file handle / whatever, that is fine, but don’t break the abstraction by then treating the curated resource as if it were the curator.