user2533527 user2533527 - 1 year ago 199
C Question

Can I fopen with shared read write?

Can I create a file in C
that will be accessible at any time in user mode?

I mean like


Can I make it with fopen in user mode ?

I want my log file to be shared read write so when my program is running I can still open it and view the logs while my program still writing to there.

Answer Source
#include <stdlib.h>
#include <stdio.h>
#include <share.h>
#include <stdlib.h>

FILE *FPlogHigh; 

int main(int argc, char **argv)
    FPlogHigh = _fsopen("filename.txt", "a+",_SH_DENYWR);
    if (FPlogHigh)
        fprintf(FPlogHigh,"\nHello log started\n");

I opening and closing the file handle each time I want to write there. It allows me to access the log file from any other program. I also can not change log in other program while this 1 is writing to log file but as it closes FCLOSE(); I can edit a+ stands for append it writes to the end of the file each times it opens.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download