Getc or Getchar is not reading data

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Emmanuel Delahaye

    #16
    Re: Getc or Getchar is not reading data

    Pradyut a écrit :
    [color=blue]
    > This is not a good solution but a works well[/color]

    No, it doesn't work at all.
    [color=blue]
    > fflush(stdin);[/color]

    This statement invokes an undefined behaviour. It has been explained
    before in the thread that you should have read before posting...

    --
    A+

    Emmanuel Delahaye

    Comment

    • Emmanuel Delahaye

      #17
      Re: Getc or Getchar is not reading data

      Pradyut a écrit :

      <nothing>

      Because you have answered after the signature separator, none of your
      prose has been quoted (Thunderbird). Please don't do that.

      --
      A+

      Emmanuel Delahaye

      Comment

      • Flash Gordon

        #18
        Re: Getc or Getchar is not reading data

        Pradyut wrote:[color=blue]
        > --
        > Pradyut http://pradyut.tk[/color]

        <snip>

        Your signature (i.e. the bit I've quoted part of above) belongs *below*
        the post, not above it. A number of news readers automatically remove
        signatures when replying (or even when displaying) so putting the
        signature above is a real pain for some people. Search for quotefix if
        you want to get OE to behave a bit better.
        [color=blue][color=green][color=darkred]
        >> > HI,
        >> > Below is my program. I compiled it through g++. Now strange thing is,
        >> > getc is not reading the data instead its printing the previously read
        >> > data ! Please some one let me know whats wrong.
        >> >[/color][/color]
        >
        > This is not a good solution but a works well
        >
        > #include<stdio. h>
        > int main()
        > {
        >
        > int a;
        > char c;
        > scanf("%d",&a);
        > printf("%d",a);
        > fflush(stdin);[/color]

        No, no, a thousand times no. We've just had a few posts saying the
        fflush is defined for output streams only, so *why* are you suggesting
        using it on an input stream?
        [color=blue]
        > c = getc(stdin);
        > printf("\nThis is the charachter %c",c);
        > return 0;
        > }
        >
        > Although it's a very typical solution to such problems[/color]

        <snip>

        It may be typical amongst those who have learnt from bad books, but it
        is not typical amongst those who have a good understanding of C.
        --
        Flash Gordon
        Living in interesting times.
        Although my email address says spam, it is real and I read it.

        Comment

        • M.B

          #19
          Re: Getc or Getchar is not reading data

          this dosent work
          you cannot do fflush on input buffers
          see "man fflush" first

          Comment

          • pemo

            #20
            Re: Getc or Getchar is not reading data


            "Keith Thompson" <kst-u@mib.org> wrote in message
            news:lnr77qfja1 .fsf@nuthaus.mi b.org...[color=blue]
            > "pemo" <usenetmeister@ gmail.com> writes:[color=green]
            >> <mailursubbu@gm ail.com> wrote in message
            >> news:1136201933 .107953.34480@g 49g2000cwa.goog legroups.com...[color=darkred]
            >>> Then how can I read the Integer and the Character ?? Any solution ???
            >>> Its happening consistantly on windows as well as on Linux...[/color]
            >>
            >> scanf(...)
            >>
            >> while(getchar() != '\n')
            >> ;
            >>
            >> c = getchar();[/color]
            >
            > If getchar() returns EOF before returning '\n', this is an infinite loop.
            >
            > What is the purpose of that last line? It reads the first character
            > on the line following the one your just read; was that what you
            > intended?[/color]

            Oops - yes, it was intended, but it shouldn't have been copied into my post.


            Comment

            Working...