SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Enthusiast
    Join Date
    Nov 2006
    Posts
    99
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Newbie C language question

    Hi all!

    I have some biginner question:
    I've started to learn C from the Kernighan&Ritchie book, using Pelles C compiler. Why this code (from the book) dont work:

    #include <stdio.h>
    /* count characters in input; 1st version */
    main()
    {
    long nc;
    nc = 0;
    while (getchar() != EOF)
    ++nc;
    printf("%ld\n", nc);
    }

    It should count chars from the input and then print the result (I hope). But when I compile it and start the script all I can do is write some input but it doesnt print anything...

    Hope somebody can help me.
    Thanks

    Bosko

  2. #2
    SitePoint Enthusiast
    Join Date
    Nov 2006
    Posts
    99
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I've got answer from another forum:
    In console I have to type Enter Ctrl+z Enter to indicate an EOF

    or see this
    http://www.fredosaurus.com/notes-cpp/io/eof.html


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •