Code::Blocks Forums

User forums => Help => Topic started by: zygote on February 23, 2012, 01:34:31 pm

Title: How To Input EOF
Post by: zygote on February 23, 2012, 01:34:31 pm
Hi there,

I just got started with learning C. I've 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? I need that window to stay open NOW!

Thanks for taking the time to read my issue. I appreciate it.
Title: Re: How To Input EOF
Post by: MortenMacFly on February 23, 2012, 02:26:09 pm
Could you please tell me how to run the above program correctly in Code Blocks? I need that window to stay open NOW!
Did you try to run it in a console without IDE? Did you then enable to run it in a console from with C::B?

However, as you didn't state any C::B version information I can't tell you how to solve.
Title: Re: How To Input EOF
Post by: zygote on February 23, 2012, 03:36:22 pm
I'm running version 1-8.c.

I don't really understand what you're talking about.  ???

I ran the code by pressing F9 (Build and Run).

I'm really sorry if these questions are downright elementary. I just got started with programming.  :-[
Title: Re: How To Input EOF
Post by: oBFusCATed on February 23, 2012, 03:50:51 pm
There is no such version of codeblocks. So please be exact.
Also type cmd in the start menu's search box, press enter, then execute your program from there.
If you don't know how to handle the console, please search for a tutorial!
Title: Re: How To Input EOF
Post by: zygote on February 23, 2012, 04:25:06 pm
The version is 10.05 rev 6283. Got it mixed up earlier.  ::)