A
A
Alexander Rybakov2018-09-26 16:35:20
C++ / C#
Alexander Rybakov, 2018-09-26 16:35:20

Program not ending?

Why doesn't the program terminate as soon as it displays the sequence. The program's task has been completed, but it is waiting for input.5bab8ae80488e791872068.jpeg

#include <stdio.h>
#include <stdlib.h>
#include <conio.h>

int main() 
{
  char c;
  int i;
  printf("Vvedite stroky\n");
  i = 0;
  c = getchar();
  while (c!=EOF)
  {
    if(c == ':'){
      i++;
      c = getchar();
    }	
    if(i == 1){
      putchar(c);
    }
    c = getchar();
  };

  printf("\n");	
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Mercury13, 2018-09-26
@Mercury13

Because end of console from keyboard is OS dependent and for Windows it is Ctrl+Z.
Pressing enter does not pass EOF to the stream.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question