Thread: Introduction in c dennis

  1. #1
    Registered User
    Join Date
    May 2017
    Posts
    1

    Question Introduction in c dennis

    hello, i want to learn c, i reviewed the book of Brian W. and i have a questions in the next code:

    Code:
    #include <stdio.h>
    int main(void ){
    int c;
    long n;
    n=0;
    for(n=0;(c=getchar())!= EOF;n++ )
    ;
    printf("fin %ld",n);
    return 0;
    }
    the problem is when i introduce a character, for example blank space and then continue loop. it doesn´t break. why ?
    sorry for my enlgish.

  2. #2
    Registered User
    Join Date
    Jun 2015
    Posts
    1,640
    The loop will continue until the getchar() function detects the end-of-file condition. From the keyboard, you signal that condition by pressing a special key combination which is Ctrl-Z on Windows (which I believe needs to be entered at the beginning of a line), or Ctrl-D on *nix.

  3. #3
    Registered User
    Join Date
    Apr 2017
    Location
    Iran
    Posts
    138
    Please use proper indentation for the code.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Structure usage from Dennis Ritchie's manual
    By goodluck in forum C Programming
    Replies: 1
    Last Post: 01-10-2012, 11:31 AM
  2. Lexical convention from Dennis Ritchie's manual
    By goodluck in forum C Programming
    Replies: 3
    Last Post: 01-04-2012, 11:46 AM
  3. Dennis M. Ritchie
    By kermit in forum General Discussions
    Replies: 41
    Last Post: 10-17-2011, 04:39 PM
  4. The Father of C has Died Dennis Richie
    By zerokernel in forum C Programming
    Replies: 1
    Last Post: 10-14-2011, 09:15 AM
  5. Introduction to MFC
    By Unregistered in forum Windows Programming
    Replies: 2
    Last Post: 12-06-2001, 11:35 AM

Tags for this Thread