Re: getc hanging

Discussion in 'C Programming' started by Irrwahn Grausewitz, Aug 31, 2003.

  1. (Chandrashekar Tippur) wrote in
    <>:

    <SNIP>

    > if ((fds= fopen(scriptname,"r")) != NULL)
    > {
    > while (( i = fgetc(fds)) != EOF || ferror(fds) ==0 )

    ^^
    ITYM: &&
    > {
    > putc(i,stdout);
    > }
    > fclose(fds);
    > }
    >


    --
    My opinions are not those of my ex-employer.
    Irrwahn Grausewitz, Aug 31, 2003
    #1
    1. Advertising

  2. Irrwahn Grausewitz <> wrote in
    <>:
    >> while (( i = fgetc(fds)) != EOF || ferror(fds) ==0 )

    > ^^
    > ITYM: &&


    BTW:
    Calling ferror() is redundant, as fgetc() will return
    EOF if the error indicator of the stream is set, so
    writing:

    while (( i = fgetc(fds)) != EOF )

    is absolutely sufficient.

    And, of course, you declared i as int, I hope. :)))

    --
    My opinions are not those of my ex-employer.
    Irrwahn Grausewitz, Aug 31, 2003
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. spike
    Replies:
    9
    Views:
    294
    Martien Verbruggen
    Feb 27, 2004
  2. PL

    detect Ctrl+C with getc ?

    PL, May 25, 2004, in forum: C Programming
    Replies:
    2
    Views:
    860
  3. William L. Bahn

    getc() vs. fgetc()

    William L. Bahn, Jul 14, 2004, in forum: C Programming
    Replies:
    13
    Views:
    1,758
    Dave Thompson
    Jul 21, 2004
  4. Bill Cunningham

    getc and ungetc

    Bill Cunningham, Nov 18, 2004, in forum: C Programming
    Replies:
    8
    Views:
    386
    Malcolm
    Nov 22, 2004
  5. TTroy
    Replies:
    11
    Views:
    714
    Dik T. Winter
    Mar 14, 2005
Loading...

Share This Page