Thread: how to read and write from two different programs

  1. #1
    Unregistered
    Guest

    Question how to read and write from two different programs

    Hello,

    I have been trying to read data from a text file simultaniously as the data is being written to the text file. I am trying to use two C programs to accomplish this.

    I set one program to

    out = fopen("press.out","w+");


    and in the other

    out = fopen("press.out", "r");


    but it only reads the data when I close the first program. Is there any way to get around this?

    Thanks

  2. #2
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    You'll probably need to fflush() the output.....
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  3. #3
    Registered User
    Join Date
    Jul 2002
    Posts
    45
    i think u can't do read and write at a time on same file......
    u r distrubing file pointers by doing that........ use file locking, if u r not willing to do the both read and write at a time.....do it one by one....... but before that check the file is bussy or nat... if it is bussy then wait..while file_status != closed;
    but this is for read or write at a time and not for both at a time.

  4. #4
    Im back! shaik786's Avatar
    Join Date
    Jun 2002
    Location
    Bangalore, India
    Posts
    345
    1.) Open the file in "a+" mode instead of "w+" mode.
    2.) As Hammer said, use fflush() on the write end.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 6
    Last Post: 04-17-2009, 04:41 PM
  2. Problems with fstream, one variabile for write and read
    By Smjert in forum C++ Programming
    Replies: 3
    Last Post: 02-03-2009, 10:19 PM
  3. read write lock in C#
    By George2 in forum C# Programming
    Replies: 0
    Last Post: 04-16-2008, 08:49 AM
  4. Replies: 3
    Last Post: 03-04-2005, 02:46 PM
  5. Serial Communications in C
    By ExDigit in forum Windows Programming
    Replies: 7
    Last Post: 01-09-2002, 10:52 AM