Thread: fgets is not reading properly

  1. #1
    User
    Join Date
    Jan 2006
    Location
    Canada
    Posts
    499

    Unhappy fgets is not reading properly

    I'm trying to read 1 line at a time from my file, and in the documentations it said that fgets reads one line at a time and returns a pointer to that line. So I tried it, but it wouldn't stop reading until it reached 255 bytes, even though there were lots of new lines.

    Anybody know anything going wrong? Here is what it looks like:

    Code:
    fgets(stream, 255, file);

  2. #2
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    it should work as expected. unless perhaps the text file was created by a unix program and you're running windows or vice-versa, since they use different values for newlines.
    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;
    }

  3. #3
    User
    Join Date
    Jan 2006
    Location
    Canada
    Posts
    499
    Thanks.....got it to work. It so happened I was using someone else's text file and trying to load it into my program. When I tried creating my own text file, it worked like it should.

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Post a whole program, not just one line.

  5. #5
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    fgets doesn't care if you make the file or if some one else does.


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

  6. #6
    User
    Join Date
    Jan 2006
    Location
    Canada
    Posts
    499
    I'm not going to post the code. It works perfectly. What happened was I was using a text file from another OS. When I rewrote the text file, it worked perfectly. ;-)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 3
    Last Post: 03-05-2009, 03:14 AM
  2. Strange behavior if I use fgets() after fscanf()
    By avi2886 in forum C Programming
    Replies: 5
    Last Post: 02-17-2009, 04:20 PM
  3. Replies: 7
    Last Post: 02-02-2009, 07:27 AM
  4. fgets crashing my program
    By EvBladeRunnervE in forum C++ Programming
    Replies: 7
    Last Post: 08-11-2003, 12:08 PM
  5. help with fgets
    By Unregistered in forum C Programming
    Replies: 2
    Last Post: 10-17-2001, 08:18 PM