Need help with displaying the output

This is a discussion on Need help with displaying the output within the C Programming forums, part of the General Programming Boards category; Code: #include <stdio.h> main() { int c, n1; n1 = 0; while ((c = getchar()) != EOF) if (c == ...

  1. #1
    Registered User
    Join Date
    Feb 2013
    Posts
    3

    Question Need help with displaying the output

    Code:
    #include <stdio.h>
    
    main()
    {
        int c, n1;
    
        n1 = 0;
        while ((c = getchar()) != EOF)
            if (c == '\n')
                ++n1;
        printf("%d\n", n1);
    }
    I have a more complicated program I'm wishing to have display the output, however, to save some time I'm using an example of a shorter version. Please help count the lines in input and display the output in terminal when ./program is executed after compilation.
    To help count and compute lines, words and within arrays.
    Thanks,
    yoda

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    22,302
    What is the problem?
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Feb 2013
    Posts
    3
    It's not showing the output on Fedora 18's terminal

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    22,302
    It looks like it should work (though you should declare main as returning an int). Did you trigger EOF at the terminal?
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    Registered User
    Join Date
    Feb 2013
    Posts
    3
    Wow..
    I got everything to run from the code I didn't paste here. Long day.. I never triggered EOF..
    Also, sorry for the sloppy code haha I went back and declared main. Thanks, laserlight

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help displaying output from function
    By c++prog in forum C++ Programming
    Replies: 3
    Last Post: 11-11-2008, 10:01 PM
  2. Help with displaying output
    By tallguy in forum C++ Programming
    Replies: 1
    Last Post: 03-28-2007, 07:38 PM
  3. Output Displaying Incorrectly
    By Zildjian in forum C Programming
    Replies: 3
    Last Post: 11-21-2003, 10:59 AM
  4. displaying binary output
    By clancyPC in forum C Programming
    Replies: 1
    Last Post: 10-14-2003, 08:32 AM
  5. Trouble displaying output
    By Guti14 in forum C++ Programming
    Replies: 1
    Last Post: 10-02-2003, 09:39 PM

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