News:

When registered with our forums, feel free to send a "here I am" post here to differ human beings from SPAM bots.

Main Menu

How To Input EOF

Started by zygote, February 23, 2012, 01:34:31 PM

Previous topic - Next topic

zygote

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:

#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.

MortenMacFly

Quote from: zygote on February 23, 2012, 01:34:31 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.
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: [url="https://www.codeblocks.org/docs/main_codeblocks_en.html"]https://www.codeblocks.org/docs/main_codeblocks_en.html[/url]
C::B FAQ: [url="https://wiki.codeblocks.org/index.php?title=FAQ"]https://wiki.codeblocks.org/index.php?title=FAQ[/url]

zygote

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.  :-[

oBFusCATed

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!
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

zygote

The version is 10.05 rev 6283. Got it mixed up earlier.  ::)