Thread: Making a File to be read

  1. #1
    Registered User
    Join Date
    Sep 2003
    Posts
    17

    Unhappy Making a File to be read

    Hi:

    My program creates a file to store the read data in the parallel port.
    I know how to do it with fopen and fclose,
    but the problem is because the program makes an infinite loop and i need to be able to read the file whenever i want and with these functions i can't see it until the program finishes.

    Does anyone know how to append the lines in the file and i can read it while the program is still running?

    A Man can be whatever he wants to
    be

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Code:
    for( ;; )
    {
        FILE *fp = fopen( "foo", "a+" );
        char buf[] = "hello\n";
        fwrite( buf, sizeof(char), strlen(buf), fp );
        fclose( fp );
    }
    Or just don't even bother reopening and closing, and just rewind and seek to wherever you need. Naturally you're better off with binary files if you're going to be seeking.

    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Registered User
    Join Date
    Sep 2003
    Posts
    17
    Thanks a lot. I'll try this!!!

    A Man can be whatever he wants to
    be

  4. #4
    Registered User
    Join Date
    Jan 2002
    Location
    Vancouver
    Posts
    2,212
    while (1) pwns for ( ;; ) (IMO)

  5. #5
    Obsessed with C chrismiceli's Avatar
    Join Date
    Jan 2003
    Posts
    501
    did you just say pwns, :)
    yeah, i use while(1) over for(;;) to, more logical to me.

  6. #6
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >while (1) pwns for ( ;; ) (IMO)
    Except when you're using an anal compiler that flags a warning with while (1). I prefer a clean compile, and for (;;) has never given me a warning on any of my compilers.
    My best code is written with the delete key.

  7. #7
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Originally posted by Prelude
    >while (1) pwns for ( ;; ) (IMO)
    Except when you're using an anal compiler that flags a warning with while (1). I prefer a clean compile, and for (; has never given me a warning on any of my compilers.
    Plus a while takes 8 characters, and for takes seven, squashing white space in both.

    Quzah.
    Hope is the first step on the road to disappointment.

  8. #8
    Been here, done that.
    Join Date
    May 2003
    Posts
    1,164
    Originally posted by quzah
    Plus a while takes 8 characters, and for takes seven, squashing white space in both.

    Quzah.
    Sheesh!
    Definition: Politics -- Latin, from
    poly meaning many and
    tics meaning blood sucking parasites
    -- Tom Smothers

  9. #9
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    Originally posted by WaltP
    Sheesh!
    Heh, can't get any more efficient than that!
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  10. #10
    Been here, done that.
    Join Date
    May 2003
    Posts
    1,164
    Originally posted by Sebastiani
    Heh, can't get any more efficient than that!
    In the code section, you sure can (if you ignore the definition area):
    Code:
    #define L8 while(1)
    
    int main()
    {
        L8
        {
        }
         return 0;
    }
    Definition: Politics -- Latin, from
    poly meaning many and
    tics meaning blood sucking parasites
    -- Tom Smothers

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Newbie homework help
    By fossage in forum C Programming
    Replies: 3
    Last Post: 04-30-2009, 04:27 PM
  2. Can we have vector of vector?
    By ketu1 in forum C++ Programming
    Replies: 24
    Last Post: 01-03-2008, 05:02 AM
  3. Inventory records
    By jsbeckton in forum C Programming
    Replies: 23
    Last Post: 06-28-2007, 04:14 AM
  4. Encryption program
    By zeiffelz in forum C Programming
    Replies: 1
    Last Post: 06-15-2005, 03:39 AM
  5. How to convert char read from file into string
    By cruxxe in forum C Programming
    Replies: 7
    Last Post: 05-22-2002, 02:09 PM