c - Why this getchar() doesn't work properly? -


this question has answer here:

can tell me why line o = getchar(); works first time , once works, once it's not?

#include <stdio.h>  int main(void) {     char o;      (int = 1; > 0; i++)     {         printf("%d\n", i);          if (i % 10 == 0)         {             printf("do want continue? (y/n): ");             o = getchar();             if (o == 'n')                 break;         }     }      return 0; } 

first of all, getchar() returns int, may not fit char. change

char o; 

to

int o = 0; 

then, come point of skipping, well, not skip. when press key , press enter, newline press of enter key serves feed getchar() in every second iteration of loop.


Comments

Popular posts from this blog

Capture and play voice with Asterisk ARI -

java - Why database contraints in HSQLDB are only checked during a commit when using transactions in Hibernate? -

visual studio - Installing Packages through Nuget - "Central Directory corrupt" -