How To Input EOF In Code Blocks

This is a discussion on How To Input EOF In Code Blocks within the C Programming forums, part of the General Programming Boards category; Hi there I just got started with learning C. I'm having trouble with entering the EOF character to get the ...

  1. #1
    Registered User
    Join Date
    Feb 2012
    Posts
    4

    Question How To Input EOF In Code Blocks

    Hi there

    I just got started with learning C. I'm having trouble with entering the EOF character to get the desired output. I've tried CTR+Z and CTR+C without any success. The window just closes immediately. The code I'm trying to run is:


    Code:
    #include <stdio.h>
    
    int main(void)
    {
      int c;
      int inspace;
    
      inspace = 0;
      while((c = getchar()) != 48)
      {
        if(c == ' ')
        {
          if(inspace == 0)
          {
            inspace = 1;
            putchar(c);
          }
        }
    
    
        if(c != ' ')
        {
          inspace = 0;
          putchar(c);
        }
      }
    
      return 0;
    }


    I'm running Windows 7 64 bit. I use F9 to run the code.


    Could you please tell me how to run the above program correctly in Code Blocks?

    Thanks for taking the time to read my issue. I appreciate it.

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    24,850
    You can trigger EOF at the command prompt in Windows by entering CTRL+Z on a new line.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Feb 2012
    Posts
    4
    So how should I run my .cbp file via the command prompt in Windows?

  4. #4
    Registered User manasij7479's Avatar
    Join Date
    Feb 2011
    Posts
    2,605
    Quote Originally Posted by zygote View Post
    So how should I run my .cbp file via the command prompt in Windows?
    Not the cbp file.
    When you run the program by pressing F9, at that window.

  5. #5
    Registered User
    Join Date
    Feb 2012
    Posts
    4
    Quote Originally Posted by manasij7479 View Post
    Not the cbp file.
    When you run the program by pressing F9, at that window.
    I tried that. When I press CTRL+Z, all I get is "^Z" printed with the window still open.

  6. #6
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Why are you even trying to input EOF? You aren't actually testing for it in your program anywhere. CTRL+C is not EOF. EOF is typically CTRL+D or CTRL+Z depending on your OS/shell. Also, why are you testing for 48? If you want to test for a specific character, put in the character:
    Code:
    if( c == '0' )
        ...

    Quzah.
    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help with code::blocks
    By Souradeep in forum C++ Programming
    Replies: 6
    Last Post: 12-22-2010, 03:48 AM
  2. Code::Blocks
    By bijan311 in forum C++ Programming
    Replies: 2
    Last Post: 01-26-2010, 05:36 PM
  3. Code::Blocks Help
    By rakeshkool27 in forum C Programming
    Replies: 0
    Last Post: 01-16-2010, 08:25 AM
  4. code::blocks
    By wart101 in forum Tech Board
    Replies: 4
    Last Post: 01-15-2007, 07:38 AM

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