C

Topic: Files

How can I open a file so that other programs can update it at the same time?

Your C compiler library contains a low-level file function called sopen() that can be used to open a file in shared mode. Beginning with DOS 3.0, files could be opened in shared mode by loading a special program named SHARE.EXE. Shared mode, as the name implies, allows a file to be shared with other programs as well as your own.

Using this function, you can allow other programs that are running to update the same file you are updating.

The sopen() function takes four parameters: a pointer to the filename you want to open, the operationalmode you want to open the file in, the file sharing mode to use, and, if you are creating a file, the mode to create the file in. The second parameter of the sopen() function, usually referred to as the 'operation flag' parameter, can have the following values assigned to it:
Constant Description O_APPEND Appends all writes to the end of the fileO_BINARY Opens the file in binary (untranslated) modeO_CREAT If the file does not exist, it is createdO_EXCL If the O_CREAT flag is used and the file exists, returns an errorO_RDONLY Opens the file in read-only modeO_RDWR Opens the file for reading and writingO_TEXT Opens the file in text (translated) modeO_TRUNC Opens an existing file and writes over its contentsO_WRONLY Opens the file in write-only modeThe third parameter of the sopen() function, usually referred to as the 'sharing flag,' can have the following values assigned to it:Constant DescriptionSH_COMPAT No other program can access the fileSH_DENYRW No other program can read from or write to the fileSH_DENYWR No other program can write to the fileSH_DENYRD No other program can read from the fileSH_DENYNO Any program can read from or write to the fileIf the sopen() function is successful, it returns a non-negative number that is the file?s handle. If an error occurs, '1 is returned, and the global variable errno is set to one of the following values:Constant DescriptionENOENT File or path not foundEMFILE No more file handles are availableEACCES Permission denied to access fileEINVACC Invalid access codeConstant Description

Browse random answers:

What is File Mode?.Types Of file mode?.What is Pointer?.which one is most useful in Structure or Unoin?
How can you restore a redirected standard stream? 
how to read a file line by line and print it reverse 
WRITE C PROGRAMME TO CREATE A FILE AND READ A FILE. 
How to obtain a path of the given file?
If errno contains a nonzero number, is there an error?
What is a stream?
How do you redirect a standard stream?
How would you use the functions fseek(), freed(), fwrite() and ftell()?
What is a file?
what are the types of file?
What is meant by file opening?
What is a file pointer?
How is a file closed ?
What is a random access file?
how to merge to file in c? 
Can include files be nested?
Write a program for creating your own header file and library function?
How can I open a file so that other programs can update it at the same time?
How can I create the batch files? What is the purpose batch file and use of it? 
How can we read/write structures from/to data files? 
In header files whether functions are declared or defined?
What will be the content of 'file.c' after executing the following program?#include<stdio.h>
int main(){ 
FILE *fp1, *fp2; 
fp1=fopen("file.c", "w"); fp2=fopen("file.c", "w"); 
fputc('A', fp1); 
fputc('B', fp2); 
fclose(fp1); 
fclose(fp2); 
return 0;
}
If the file 'source.txt' contains a line "Be my friend" which of the following will be the output of below program?
#include<stdio.h>
int main(){ 
 FILE *fs, *ft; 
char c[10]; 
fs = fopen("source.txt", "r"); 
c[0] = getc(fs); 
fseek(fs, 0, SEEK_END); 
fseek(fs, -3L, SEEK_CUR); 
fgets(c, 5, fs); 
puts(c); return 0;
}
What will be the output of the program ?#include<stdio.h>int main(){ 
FILE *ptr; char i; 
 ptr = fopen("myfile.c", "r"); while((i=fgetc(ptr))!=NULL) printf("%c", i); return 0;}
Out of fgets() and gets() which function is safe to use and why?
In a file contains the line "I am a boyrn" then on reading this line into the array str using fgets(). What will str contain?
Which of the following operations can be performed on the file "NOTES.TXT" using the below code?

FILE *fp;fp = fopen("NOTES.TXT", "r+");
What is the purpose of ftell ?
What is the purpose of rewind() ?
What is the use of header file in c?
What are header files? Are functions declared or defined in header files ?
When we open a file, how does functions like fread( )/fwrite( ), etc. get to know from where to read or to write the data?
How to obtain a path of the given file?