Writing to a file:
if(fp)
{
// fp -> handle to the file
fputs("Satya Pawan Kartik", fp);
fclose(fp);
}
Reading from the file:
for(;;)
{
// fp -> handle to the file
while(fgets(line, sizeof line, fp))
{
printf("%s\n", line);
}
}
Let's say that the program writing to the text file is called write
and the program reading the file is called read
.
read
obviously runs forever. Executing write
displays the changes made by it to the text file by read
. If required write
can be modified to run forever and display the line written by it through a for loop counter
. The same changes will be evidently visible in read
.
So yes it is possible to write and read with 2 programs simultaneously.