Please help me figure out how to properly close the file in this function? If you frequently call the function, you get serious errors “Error opening file: Too many open files”

 int urez(){ int fh; fh=open("d:\\1.txt", O_RDWR|O_CREAT, S_IREAD|S_IWRITE); chsize(fh,2); /* как правильно закрыть файл? fclose(???) fclose(fh); --- не работает */ return 0; } 
  • Locked! Understood himself. Who cares the correct answer "close (fh);" - alexl1720p

3 answers 3

close (fh);

For fopen () fclose (), for popen () pclose (), for opendir (), closedir (), for open () and socket () close ().

In general, look carefully at the result types of functions and SEE ALSO in man.

    better use std :: ifstream, std :: ofstream. everything is somehow easier with them ..

      It is necessary to use a file variable, i.e.

       FILE *fh; //И потом так: fh = fopen("d:\1.txt", "rt"); 

      We were taught at the university so :)

      • Well, the teachers ... - avp
      • What's wrong? - metazet