Simple programm error

This is a discussion on Simple programm error within the C Programming forums, part of the General Programming Boards category; Code: #include <stdio.h> main() { int c, nl; nl =0; while (( c = getchar()) != EOF ) if ( ...

  1. #1
    Registered User datainjector's Avatar
    Join Date
    Mar 2002
    Posts
    356

    Simple programm error

    Code:
    #include <stdio.h>
    
    main()
    {  
         int c, nl;
    
         nl =0;
         while (( c = getchar()) != EOF )
                   if ( c == '\n' )
                       ++nl;
         printf( "%d\n",nl );
    }
    Okay this programm was taken from K&R book .... after pressing ctrl - z it does not print the number of lines out ??? why i have tried it on 2 compilers Dev-c++ and borland 5.5
    "I wish i could wish my wishs away"

    "By indirections find directions out" -- William Shakespears

    "Do what thou wilt shall be the whole of the law" -- Crowley "THE BEAST 666"

    Mizra -> love = Death...
    RDB(Rocks yooo)..

    http://www.cbeginnersunited.com

    Are you ready for the Trix ???

  2. #2
    Unleashed
    Join Date
    Sep 2001
    Posts
    1,765
    Actually, what you stated works fine here.
    The world is waiting. I must leave you now.

  3. #3
    CS Author and Instructor
    Join Date
    Sep 2002
    Posts
    511
    Looking at the K&R book you forgot to add

    Code:
    return 0;
    at the end of the main function.

    Mr. C.

  4. #4
    Registered User datainjector's Avatar
    Join Date
    Mar 2002
    Posts
    356

    lo

    Originally posted by Mister C
    Looking at the K&R book you forgot to add

    Code:
    return 0;
    at the end of the main function.

    Mr. C.
    Looking at the book it does not return 0

    DaIn
    "I wish i could wish my wishs away"

    "By indirections find directions out" -- William Shakespears

    "Do what thou wilt shall be the whole of the law" -- Crowley "THE BEAST 666"

    Mizra -> love = Death...
    RDB(Rocks yooo)..

    http://www.cbeginnersunited.com

    Are you ready for the Trix ???

  5. #5
    Unleashed
    Join Date
    Sep 2001
    Posts
    1,765
    No return 0?
    No int main?

    I just pressed enter a few times, then ctrl+z, then enter.
    The world is waiting. I must leave you now.

  6. #6
    moi
    moi is offline
    Registered User moi's Avatar
    Join Date
    Jul 2002
    Posts
    946
    Originally posted by Shadow
    No return 0?
    No int main?

    I just pressed enter a few times, then ctrl+z, then enter.
    any function without an explicit type is assumed to return int.

    but the no "return 0;" is inexcusable.
    hello, internet!

  7. #7
    moi
    moi is offline
    Registered User moi's Avatar
    Join Date
    Jul 2002
    Posts
    946
    Originally posted by Shadow
    No return 0?
    No int main?

    I just pressed enter a few times, then ctrl+z, then enter.
    any function without an explicit type is assumed to return int.

    but the no "return 0;" is inexcusable.
    hello, internet!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Making C DLL using MSVC++ 2005
    By chico1st in forum C Programming
    Replies: 26
    Last Post: 05-28-2008, 01:17 PM
  2. Crazy errors caused by class, never seen before..
    By Shamino in forum C++ Programming
    Replies: 2
    Last Post: 06-10-2007, 11:54 AM
  3. DX - CreateDevice - D3DERR_INVALIDCALL
    By Tonto in forum Game Programming
    Replies: 3
    Last Post: 12-01-2006, 06:17 PM
  4. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  5. UNICODE and GET_STATE
    By Registered in forum C++ Programming
    Replies: 1
    Last Post: 07-15-2002, 03:23 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21